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,27 +1,27 @@ 1 - *Meaningful andDescriptiveNames2 - * Choose names carefully, as if naming a child.3 - Namesshouldreflect thecode'spurposeclearly. For example, use unorderedNumbers and orderedNumbers instead of aenericnumbers.4 -* Avoid Misinformation5 - Steer clear of ambiguous,easilyconfusednamesorcharacters(e.g.,lvs.1,O vs. 0).6 -* ClarityinDifferences7 - Distinguish namesdistinctly,avoiding similarexpressionsandredundantwords(e.g., a,an,the, info,data).8 -* PronounceableandSearchableNames9 - Use namesthatareeasytopronouncediscuss.10 - lengthshouldmatch itscope:shortfor local loops,longerforbroader usage.11 -* No Encodings orMentalMappings12 - * Avoidincludingtype or scopeinformationin names.13 - * Namesshouldbe clearwithout requiringmental translation.14 -* Naming ConventionsforClassesand Methods15 - lass names:Use nounsornounphrases.16 - * Methodnames: Useverbs or verb phrases, adheringtostandards likeJavaBean (get, set, is,has).Utilize descriptive function names insteadof overloaded constructors.17 -* AvoidInappropriate Humor and Ambiguities18 - Refrainfromhumorousnames.19 - Chooseonewordper conceptto maintain consistency(e.g., alwaysse "get"insteadofalternating with "fetch" or "retrieve").20 - *Avoidpunsand ambiguous terms(like"add"foradditionorappending).21 -* Domain-SpecificNaming22 - * Usetechnicalterms(solution domain)for clarity amongprogrammers.23 - Useterms from theproblem domainwhen no technical equivalentsexist, aiding domainperts.24 -* Context andSimplicityinNaming25 - Providemeaningful contextthroughcombined variable and method names.26 - * Avoidunnecessarycontext;optfor shorter, meaningfulnames.27 - Beopento renamingfor clarityandimprovement.1 +Names should be chosen as carefully as the name of his firstborn child. Implicity: It should be self-evident 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 +* Avoid humorous names. 15 +* Choose one word per concept. 16 + * "get" instead of "fetch" and "retrieve". 17 +* No puns. 18 +* Avoid ambiguities as in the word "add" (addition or adding). 19 +* Use names of the solution domain. 20 + * Programmers will read your code, so use technical language. 21 +* Use names of the problem domain. 22 + * If there are no terms from computer science. Then at least domain experts can refer to it. 23 +* Add meaningful context. 24 + * Together with the names of other variables and methods, this context can be created. 25 +* Do not add superfluous context. 26 + * Shorter names are better than longer ones, as long as they are clear. Names should be simple, but meaningful. 27 +* Dare to rename things. Your colleagues should be grateful for improvements.