Expressive Names

Version 1.4 by chrisby on 2023/11/17 22:01

  • Meaningful and Descriptive Names
    • Choose names carefully, as if naming a child.
    • Names should reflect the code's purpose clearly. For example, use unorderedNumbers and orderedNumbers instead of a generic numbers.
  • Avoid Misinformation
    • Steer clear of ambiguous, easily confused names or characters (e.g., l vs. 1, O vs. 0).
  • Clarity in Differences
    • Distinguish names distinctly, avoiding similar expressions and redundant words (e.g., a, an, the, info, data).
  • Pronounceable and Searchable Names
    • Use names that are easy to pronounce and discuss.
    • Name length should match its scope: short for local loops, longer for broader usage.
  • No Encodings or Mental Mappings
    • Avoid including type or scope information in names.
    • Names should be clear without requiring mental translation, meaning any effort of the programmer to get the actual purpose
  • Naming Conventions for Classes and Methods
    • Class names: Use nouns or noun phrases.
    • Method names: Use verbs or verb phrases, adhering to standards like JavaBean (get, set, is, has). Utilize descriptive function names instead of overloaded constructors.
  • Avoid Inappropriate Humor and Ambiguities
    • Refrain from humorous names.
    • Choose one word per concept to maintain consistency (e.g., always use "get" instead of alternating with "fetch" or "retrieve").
    • Avoid puns and ambiguous terms (like "add" for addition or appending).
  • Domain-Specific Naming
    • Use technical terms (solution domain) for clarity among programmers.
    • Use terms from the problem domain when no technical equivalents exist, aiding domain experts.
  • Context and Simplicity in Naming
    • Provide meaningful context through combined variable and method names.
    • Avoid unnecessary context; opt for shorter, meaningful names.
    • Be open to renaming for clarity and improvement.