Changes for page Expressive Names

Last modified by chrisby on 2023/11/18 17:45

From version 1.4
edited by chrisby
on 2023/11/17 22:01
Change comment: There is no comment for this version
To version 1.7
edited by chrisby
on 2023/11/18 16:15
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,27 +1,24 @@
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.
1 +Names should be chosen as carefully as the name of your first-born child. It should be obvious from reading the code how it works.
2 +
3 +* **Choose names that are descriptive of the purpose.** For example, a variables name should stand for one concept. Its better to have a variable `unorderedNumbers`, which is sorted and stored in `orderedNumbers` instead of saving both lists in the same variable `numbers`.
4 +* **Avoid misinformation.** For example, ambiguities, confusion with similar names or easily confused characters (l and 1, O and 0).
5 +* Make differences clear. Avoid very similar expressions and blank words are redundant (a, an, the, info, data).
6 +* **Use pronounceable names.** Programming is a social activity that people talk about with others.
7 +* **Use searchable names.** Searchable means avoiding search conflicts with other similar or even identical names. The length of a name should match the size of its scope. For local counting loops, one letter is sufficient; if the variable is used in several places in the code, it needs a longer name.
8 +* **Avoid encodings.** There should be no references to the scope or type of the variable in the name.
9 +* **Avoid mental mappings.** The name of a variable should not require mental effort to understand. For example, unusual abbreviations should be avoided.
10 +* Names of classes consist of nouns or substantivistic expressions.
11 +* Method names
12 + * They consist of a verb or an expression with a verb. Accessors, mutators, and predicates should be named after their value and follow the JavaBean standard (prefixes: get, set, is, has).
13 + * Overloaded constructors can lead to confusion, e.g. if one constructor accepts a float argument and and another one an int argument. Overloaded constructors should be declared as private and functions should be used to create instances whose names highlight the difference.
14 +* No puns or humorous names.
15 +* Choose one word for each concept. For example, if you use the word "fetch" once for a particular concept, you should consistently use "fetch" instead of synonyms such as "retrieve".
16 +* Avoid ambiguities as in the word "add" (addition or adding).
17 +*
18 +
19 +Domain-specific terms
20 + * Use terms from the solution domain. Programmers will be reading your code, so use technical language.
21 + * Use terms from the problem domain. If there are no computer science terms, at least domain experts can refer to them.
22 +* Add meaningful context. Together with the names of other variables and methods, this context can be created.
23 +* Do not add superfluous context. Shorter names are better than longer ones, as long as they are clear.
24 +* Dare to rename things. Your colleagues should be grateful for improvements.