Changes for page Expressive Names

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

From version 2.6
edited by chrisby
on 2023/11/18 17:45
Change comment: There is no comment for this version
To version 1.2
edited by chrisby
on 2023/11/17 21:53
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,30 +1,45 @@
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.
1 +1.
2 2  
3 -#### Consistency and Standardization
3 +**Meaningful and Descriptive Names**
4 + * Choose names carefully, as if naming a child.
5 + * Names should reflect the code's purpose clearly. For example, use unorderedNumbers and orderedNumbers instead of a generic numbers.
6 +1.
4 4  
5 -* **Names of classes consist of nouns** or substantivistic expressions as they express and entity.
6 -* **Method names start with a verb** because they express an action to be performed Accessors, mutators, and predicates should be named after their value and follow the standards like the JavaBean standard (prefixes: get, set, is, has). For example, getAge(), setAge(...), isFeatureXEnabled() -> boolean, hasPermissionY() -> boolean, etc.
7 -* **Use object creation functions rather than overloaded constructors**, as the latter can cause confusion. Overloaded constructors should be declared private, and more specifically named functions should be used to create instances.
8 -* **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".
9 -* **Domain-specific terms**
10 - * Use terms from the solution domain. Programmers will be reading your code, so use technical language.
11 - * Use terms from the problem domain. If there are no computer science terms, at least domain experts can refer to them.
8 +**Avoid Misinformation**
9 + * Steer clear of ambiguous, easily confused names or characters (e.g., l vs. 1, O vs. 0).
10 +1.
12 12  
13 -#### Do's
12 +**Clarity in Differences**
13 + * Distinguish names distinctly, avoiding similar expressions and redundant words (e.g., a, an, the, info, data).
14 +1.
14 14  
15 -* **Names describe purpose.** For example, it's better to have a variable `unorderedNumbers` which is sorted and then stored in `orderedNumbers` than to have a variable `numbers` to which the lists are assigned before and after sorting.
16 -* **Use pronounceable names.** Programming is a social activity that people talk about with others, so use names that are easy to use in conversation.
17 -* **Use searchable names.** Searchable means avoiding search conflicts with other independent things with the same name. 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 multiple places in the code, it needs a longer name.
18 -* **Dare to rename things.** Your colleagues should be grateful for improvements.
19 -* **Add meaningful context.** By including the names of other variables and methods, this context can be created to make its purpose clearer than without context. Names can be chosen to work well with others.
16 +**Pronounceable and Searchable Names**
17 + * Use names that are easy to pronounce and discuss.
18 + * Name length should match its scope: short for local loops, longer for broader usage.
19 +1.
20 20  
21 -#### Don'ts
21 +**No Encodings or Mental Mappings**
22 + * Avoid including type or scope information in names.
23 + * Names should be clear without requiring mental translation.
24 +1.
22 22  
23 -* **Avoid misinformation.** For example, ambiguity, confusion with similar names, or easily confused characters (l and 1, O and 0).
24 -* **Avoid encodings.** There should be no references to the scope or type of the variable in the name.
25 -* **Avoid mental mappings.** The name of a variable should not require mental effort to understand. For example, unusual abbreviations should be avoided.
26 -* **No puns or humorous names.**
27 -* **Avoid ambiguities** such as the word "add", which could have the meaning of "addition" or " adding".
28 -* **Avoid very similar expressions** to make differences clear.
29 -* **Avoid redundant empty words** (a, an, the, info, data).
30 -* **Do not add unnecessary context.** Shorter names are better than longer ones, as long as they are clear.
26 +**Naming Conventions for Classes and Methods**
27 + * Class names: Use nouns or noun phrases.
28 + * Method names: Use verbs or verb phrases, adhering to standards like JavaBean (get, set, is, has). Utilize descriptive function names instead of overloaded constructors.
29 +1.
30 +
31 +**Avoid Inappropriate Humor and Ambiguities**
32 + * Refrain from humorous names.
33 + * Choose one word per concept to maintain consistency (e.g., always use "get" instead of alternating with "fetch" or "retrieve").
34 + * Avoid puns and ambiguous terms (like "add" for addition or appending).
35 +1.
36 +
37 +**Domain-Specific Naming**
38 + * Use technical terms (solution domain) for clarity among programmers.
39 + * Use terms from the problem domain when no technical equivalents exist, aiding domain experts.
40 +1.
41 +
42 +**Context and Simplicity in Naming**
43 + * Provide meaningful context through combined variable and method names.
44 + * Avoid unnecessary context; opt for shorter, meaningful names.
45 + * Be open to renaming for clarity and improvement.