[閱讀筆記] Clean Code — Chapter5 Formatting

Vertical Formatting

  • Vertical Openness Between Concepts
    blanks between different functions, class
  • Vertical Density — close association
  • Vertical Distance
    closely related concepts should be kept vertically close to each other
    closely related concepts should not be separated into different files
  • Variable Declarations
    declared as close to their usage as possible
  • Instance Variables
    declared at the top of the class because been used in many places
    (instance variables to be declared in one well-known place)
  • Dependent Functions
    put them together following the calling order from top to bottom
  • Conceptual Affinity
    The stronger that affinity, the less vertical distance
  • Vertical Ordering
    function call dependencies to point in the downward direction

Horizontal Formatting

  • Horizontal Openness and Density
    whitespace → related/disassociate
  • Horizontal Alignment
    Aligning variables and assignments is not good → split them up
  • Indentation
  • Dummy Scopes
    Bad
    the semicolon is hard to see
  • Team Rules

An interactive engineer based in Tokyo. CG/Unity/Coding/Book Review