Skip to content

Chapter 21: Conclusion, with the Summary of Design Principles and the Summary of Red Flags

“This book is about one thing: complexity.” Its root causes are dependencies and obscurity, red flags help you spot it, a set of design ideas helps you avoid it, and an investment mindset keeps you applying them. Good design costs some extra work early, pays back quickly, and makes programming more enjoyable. This file also reproduces, in summary, the book’s two closing lists.

  • The book in four parts (the author’s own recap):
    1. Root causes of complexity: dependencies and obscurity.
    2. Red flags that reveal unnecessary complexity, such as information leakage, unneeded error conditions, and names that are too generic.
    3. Ideas for simpler systems, such as deep and generic classes, defining errors out of existence, and separating interface documentation from implementation documentation.
    4. The investment mindset needed to produce simple designs.
  • Summary of Design Principles (the book’s list):
    1. Complexity is incremental: you have to sweat the small stuff. (ch02)
    2. Working code isn’t enough. (ch03)
    3. Make continual small investments to improve system design. (ch03)
    4. Modules should be deep. (ch04)
    5. Interfaces should be designed to make the most common usage as simple as possible. (ch04, ch05)
    6. It’s more important for a module to have a simple interface than a simple implementation. (ch08, ch09)
    7. General-purpose modules are deeper. (ch06)
    8. Separate general-purpose and special-purpose code. (ch09)
    9. Different layers should have different abstractions. (ch07)
    10. Pull complexity downward. (ch08)
    11. Define errors (and special cases) out of existence. (ch10)
    12. Design it twice. (ch11)
    13. Comments should describe things that are not obvious from the code. (ch13)
    14. Software should be designed for ease of reading, not ease of writing. (ch18)
    15. The increments of software development should be abstractions, not features. (ch19)
  • Summary of Red Flags (the book’s list; the presence of any suggests a design problem):
Red flag Symptom Chapter
Shallow Module The interface isn’t much simpler than the implementation. ch04, ch13
Information Leakage A design decision is reflected in multiple modules. ch05
Temporal Decomposition Code structure follows execution order, not information hiding. ch05
Overexposure Using a common feature forces callers to learn about rare ones. ch05
Pass-Through Method A method does almost nothing but pass its arguments to a method with a similar signature. ch07
Repetition A nontrivial piece of code is repeated over and over. ch09
Special-General Mixture Special-purpose code isn’t cleanly separated from general-purpose code. ch09
Conjoined Methods You can’t understand one method’s implementation without the other’s. ch09
Comment Repeats Code Everything in the comment is obvious from the adjacent code. ch13
Implementation Documentation Contaminates Interface An interface comment describes details users don’t need. ch13
Vague Name A name is too imprecise to convey useful information. ch14
Hard to Pick Name It’s hard to find a precise, intuitive name. ch14
Hard to Describe Complete documentation for a variable or method must be long. ch15
Nonobvious Code The behavior or meaning can’t be understood easily. ch18
  • Design as a puzzle: “how can a particular problem be solved with the simplest possible structure?”
  • The reward of good design: more time in the design phase, which is fun, and less time chasing bugs in “complicated and brittle code.”
  • The learning cost: if you aren’t used to thinking about design, you’ll slow down while you learn. “Good design doesn’t really take much longer than quick-and-dirty design, once you know how.”
  • “A clean, simple, and obvious design is a beautiful thing.”
  • If your only goal is making today’s code work, design feels like drudge work. If good design is a goal, the book’s ideas make programming more fun.
  • Investments pay off in concrete ways: carefully defined modules get reused, documentation written six months ago saves time when you return, and design skill makes later designs faster.
  • Treating design as drudge work that gets in the way of making code work.
  • Spending your time chasing bugs in complicated code instead of designing.

Using the red-flag table in a code review (the practice the book recommends in ch01). Reviewing a new class, you might see:

  1. Three public methods that each call one method of another class with the same signature → Pass-Through Method. Decide which class owns the feature, then expose the lower class, redistribute, or merge (ch07).
  2. A reader class and a writer class that both parse the same file format → Information Leakage and Temporal Decomposition. Merge the format knowledge into one class (ch05).
  3. A method whose interface comment needs a paragraph about internal data structures → Implementation Documentation Contaminates Interface and possibly Shallow Module. Rewrite the comment for callers; if that’s impossible, rethink the interface (ch13, ch15).
  4. A variable named result in a method that returns nothing → Vague Name (ch14).

For each flag, stop and try alternative designs until it disappears.

  1. Judge every design decision by its effect on complexity.
  2. Keep the 15 principles and 14 red flags at hand while coding and reviewing.
  3. Accept the early slowdown of learning good design; it pays back.
  4. Aim for designs that are simple, powerful, and obvious.
  • Ch 1: red flags as the main learning tool, used with code reviews.
  • Ch 2: dependencies and obscurity.
  • Ch 3: the investment mindset.
  • All chapters: each principle and red flag is linked to its chapter above.