Chapter 1

Clean Code

The Cost of Bad Code

Bad code slows teams down. What starts as a quick hack becomes a tangled mess that takes longer and longer to change. Martin calls this the "wading" metaphor — you're not programming anymore, you're just struggling through mud.

The Grand Redesign in the Sky

When bad code reaches critical mass, teams demand a rewrite. But rewrites rarely succeed because the new system must catch up to the old one, which keeps evolving. The only real solution is to keep the code clean from the start.

What Is Clean Code?

Martin collects definitions from respected programmers:

  • Bjarne Stroustrup: Clean code does one thing well. It has focused, minimal dependencies.
  • Grady Booch: Clean code reads like well-written prose. It's crisp and matter-of-fact.
  • Dave Thomas: Clean code can be read and enhanced by others, has unit tests, and provides a minimal API.
  • Michael Feathers: Clean code looks like it was written by someone who cares.

The Boy Scout Rule

Leave the campground cleaner than you found it.

Every time you touch code, improve it a little. This continuous improvement prevents the slow decay that turns good codebases into nightmares.