Refine

Refine · Book summaries

Clean Code summary

By Robert C. Martin · 17 chapters · summarized by Refine

What it argues

Software rots because programmers make thousands of small local choices badly, and the remedy is a craft discipline of naming, small functions, honest structure and continuous cleaning applied line by line rather than any grand architectural fix.

Who it's for

A working programmer of a year or more, especially one maintaining code someone else wrote, who wants a vocabulary for what is wrong with it.

Skip it if you want architecture or system design; the scope here is the function and the class, and the Java-specific opinions on formatting and comments have aged into arguments.

Where it is thin

Chapter by chapter

  1. Clean CodeBad code slows a team asymptotically toward zero productivity, and since managers cannot judge code, the only defense is programmers who refuse to write it.
  2. Meaningful NamesA name must answer why the thing exists, what it does and how it is used, and a name that needs a comment to explain it has failed.
  3. FunctionsFunctions should be small, do exactly one thing at one level of abstraction, take as few arguments as possible, and have no side effects.
  4. CommentsComments are a failure to express yourself in code, and while a few kinds are genuinely good, most rot into lies the reader has no way to detect.
  5. FormattingFormatting is communication, and a team must agree one automated style, because readability over the years outlasts any function the code currently performs.
  6. Objects and Data StructuresObjects and data structures are opposites, not variants: objects hide data and expose behavior, data structures expose data and have no meaningful behavior, and confusing the two produces hybrids that are hard to extend in either direction.
  7. Error HandlingError handling should be separated from the main logic so completely that the happy path reads as if nothing can fail, which means exceptions rather than return codes, no nulls crossing interfaces, and wrappers around third-party error types.
  8. BoundariesThird-party code and code not yet written should be reached only through an interface you own, and learning tests plus adapters are what keep the seam between your design and someone else's from spreading through the system.
  9. Unit TestsTests are as important as production code and must be kept as clean, because a dirty test suite becomes so expensive to maintain that it is abandoned, and once tests are gone the code can no longer be safely changed.
  10. ClassesClasses should be small, and the measure of size is responsibilities rather than lines, so a class with more than one reason to change should be split into a family of small classes whose cohesion is high and whose collaborators are abstractions.
  11. SystemsSystem-level concerns such as object construction, persistence and transactions should be separated from application logic through dependency injection and aspect-like mechanisms, and system architecture can grow incrementally as long as those concerns stay decoupled.
  12. EmergenceGood design does not have to be designed in advance: following four simple rules, with passing tests first and duplication removal second, causes the qualities of SRP, dependency inversion and clean structure to emerge from the code.
  13. ConcurrencyConcurrency is a decoupling strategy with real costs, and writing it cleanly means confining shared data behind small synchronized regions, keeping threaded code separate from everything else, and treating spurious failures as genuine defects rather than flukes.
  14. Successive RefinementClean code is not written clean; it is written working and then refined in small disciplined steps, and the only way to stop code from rotting is to clean it the moment the mess appears.
  15. JUnit InternalsEven code written by expert authors carries small stains of unclear naming, hidden temporal coupling, negative conditionals and misplaced responsibility, and reviewing it line by line shows that the Boy Scout Rule applies to good code too.
  16. Refactoring SerialDateEven a well-intentioned, documented, working class carries dozens of small defects and obscurities that only a test suite plus mechanical refactoring will expose, and cleaning it is an act of professional courtesy rather than criticism.
  17. Smells and HeuristicsThe judgements exercised in the preceding case studies can be compressed into a list of named smells and rules, and the list is useful precisely because naming a smell is what lets a programmer act on a vague feeling that something is wrong.

Each chapter in Refine also has its key takeaways, a longer read with the code and diagrams kept, read-along narration, a concept map and short reviews.

Every chapter of Clean Code, read aloud and mapped

Refine launches on October 19 on iPhone, iPad and Mac.

Get early access