Changes for page Expressive Names
Last modified by chrisby on 2023/11/18 17:45
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,35 +1,27 @@ 1 -Names should be chosen as carefully as one would name their firstborn child. 2 - 3 -**Naming Conventions** 4 - 5 -* **Choose Meaningful and Descriptive Names** 6 - * Names should be descriptive of the purpose, e.g., use `unorderedNumbers` and `orderedNumbers` instead of a generic `numbers`. 7 - * Use names that reflect the solution domain and the problem domain. 8 - * Choose one word per concept (e.g. consistently use 'fetch' for the same concept, rather than mixing 'fetch' and 'retrieve'). 9 -* **Clarity and Simplicity in Names** 10 - * Names should be self-evident and avoid mental mappings or translations for clarity. 11 - * Avoid ambiguities, such as confusion with similar names or characters (e.g., l and 1, O and 0). 12 - * Make differences clear and avoid very similar expressions. 13 - * Avoid superfluous or redundant context; shorter names are better as long as they are clear. 14 -* **Practical Aspects of Naming** 15 - * Use pronounceable names so that you can easily talk with others about it. 16 - * Use searchable names, meaning names which prevent search conflicts. 17 - * The length of a name should correspond to the size of its scope. E.g. counters only used locally in loops, could be short or even single letters, but names used in a broad scope should be more descriptive and longer. 18 - * Avoid encodings, such as references to the variable's scope or type in its name. 19 - 20 -**Class and Method Naming** 21 - 22 -* **Class Names** 23 - * Should consist of nouns or noun phrases. 24 -* **Method Names** 25 - * Should consist of verbs or verb phrases. 26 - * Follow the JavaBean standard for accessors, mutators, and predicates (prefixes: get, set, is, has). 27 - * Use distinct names for overloaded constructors and prefer private constructors with distinct factory methods. 28 - 29 -**General Coding Practices** 30 - 31 -* **Avoiding Confusion and Misinformation** 32 - * Avoid humorous names, puns, and any names that might cause confusion. 33 -* **Contextual Naming** 34 - * Add meaningful context that complements other variable and method names. 35 - * Dare to rename things for clarity and improvement; colleagues should appreciate these enhancements. 1 +* **Meaningful and Descriptive Names** 2 + * Choose names carefully, as if naming a child. 3 + * Names should reflect the code's purpose clearly. For example, use `unorderedNumbers` and `orderedNumbers` instead of a generic `numbers`. 4 +* **Avoid Misinformation** 5 + * Steer clear of ambiguous, easily confused names or characters (e.g., l vs. 1, O vs. 0). 6 +* **Clarity in Differences** 7 + * Distinguish names distinctly, avoiding similar expressions and redundant words (e.g., a, an, the, info, data). 8 +* **Pronounceable and Searchable Names** 9 + * Use names that are easy to pronounce and discuss. 10 + * Name length should match its scope: short for local loops, longer for broader usage. 11 +* **No Encodings or Mental Mappings** 12 + * Avoid including type or scope information in names. 13 + * Names should be clear without requiring mental translation, meaning any effort of the programmer to get the actual purpose 14 +* **Naming Conventions for Classes and Methods** 15 + * Class names: Use nouns or noun phrases. 16 + * Method names: Use verbs or verb phrases, adhering to standards like JavaBean (get, set, is, has). Utilize descriptive function names instead of overloaded constructors. 17 +* **Avoid Inappropriate Humor and Ambiguities** 18 + * Refrain from humorous names. 19 + * Choose one word per concept to maintain consistency (e.g., always use "get" instead of alternating with "fetch" or "retrieve"). 20 + * Avoid puns and ambiguous terms (like "add" for addition or appending). 21 +* **Domain-Specific Naming** 22 + * Use technical terms (solution domain) for clarity among programmers. 23 + * Use terms from the problem domain when no technical equivalents exist, aiding domain experts. 24 +* **Context and Simplicity in Naming** 25 + * Provide meaningful context through combined variable and method names. 26 + * Avoid unnecessary context; opt for shorter, meaningful names. 27 + * Be open to renaming for clarity and improvement.