[閱讀筆記] Clean Code — Chapter5 Formatting

Question Kid
1 min readJan 25, 2021

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
    return b*b - 4*a*c;
  • Horizontal Alignment
    Aligning variables and assignments is not good → split them up
  • Indentation
  • Dummy Scopes
    while (dis.read(buf, 0, readBufferSize) != -1;Bad
    the semicolon is hard to see
  • Team Rules

--

--

Question Kid

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