Menu
Book Summaries

Clean Code

Clean code, Coder proprement, クリーンなコード,كود نظيف

English

Meaningful Names

  • Names of the classes, variables, and methods must be meaningful and clearly indicate what a method does or what an attribute is.
  • Use intention-revealing names: (int d; // elapsed time) to (int elapsedTimeInDays)
  • Avoid Disinformation: l,1,o,0 or XZYControllerForHandling, XYZControllerForStorage are so different
  • Make meaningful distinctions: math series can use (a1, a2, …aN), getActiveAccount() and getActiveAccountInfo() we dont know the difference from the naming
  • Use pronounceables names:  genydhms to generationTimestamp
  • Use searchable names: variable name with ‘e’, ‘sum’ is a poor choice, it’s hard to search; in addition to the length of a name should correspond to the size of its scope
  • Avoid encodings
  • Avoir Hungarian Notation: phoneString, tvaBoolean
  • Membre Prefixes: Avoid prefexing Interfaces and Implementations with ‘I’ or ‘Impl’
  • Avoid Mental Mapping: j, r, k, x, ll, mn, Clarity is King
  • Class names: Should have noun or noun phrase names: Customer, WikiPage, AccountParser
  • Method names: Should have verb or verb phrase nouns like: postPayment, deletePage, save. Except for accessors: set, get, is
  • Overloaded constructs: When constructors are overloaded, use factory methods with names that describes arguments: Complex.FromRealNumber(23.0)
  • Don’t be cute and don’t use slang: HolyHandGrenade, eatMyShorts
  • Pick one word per concept: fetch, retrieve and get in the same class is so confusing, the same for controller, manager, driver
  • Don’t pun: avoid using the same word for two purposes: instead add use insert or append
  • Use solution domaine names: Computer science terms, algorithm names, pattern names, math terms etc .Don’t use Problem domain names => AccountVisitor: means maybe the pattern Visitor? the same for JobQueue
  • Use problem domaine names: when you aren’t dealing with programmers use then PDN
  • Add meaningful context: city, houseNumber, state => but what does state means in our case? it’s better to use context naming like => addrCity, addrHouseNumber, addrState
  • Don’t add gratuitous context: for example if the project is for a company called GSD, don’t use it as prefix context like GSDAccountAddress

No Comments

    Leave a Reply