Book Review: Clean Code by Robert C. Martin

If you browse lists of recommended books that every software developer should read, Clean Code by Robert "Uncle Bob" Martin will come up again and again. My voice can now be added to the chorus in praise of this book.

Uncle Bob subtitles his book A Handbook of Agile Software Craftsmanship, and the theme of craftsmanship is laced throughout the book. Uncle Bob laments that too many programmers think that functioning code is good code. He asserts that many people know how to write code, but far fewer know the craft of writing Clean Code.

Uncle Bob urges the reader to take pride in their code, makes a business case for why well constructed "clean" code should always be sought, and then lays out in detail how to go about practicing the craft of professional software development.

After reading this book it's hard not to look at my own code and be embarrassed. But the book also has left me motivated to make my code better. With Clean Code's numerous examples and detailed explanations I feel well equipped to write cleaner code, if not Clean Code.

Making the Case

Clean Code starts out by making the case for why writing clean code is important. This starting assertion is emphasized throughout the rest of the book as Uncle Bob gives examples of bad code that he proceeds to clean.

While developers can be, at worst, indifferent to clean code, Uncle Bob makes a convincing argument why we should care more: clean code can be read, refactored, scaled, and debugged much more easily then dirty code. Having code with these qualities is worth the extra effort to transform functioning code to clean code.

The term Agile is used in the subtitle, but I'm not sure it's mentioned again in the book. Rather than singing the praises of agile methodologies, Uncle Bob emphasizes that the key to clean code is iteration and refactoring. Refreshingly, he doesn't talk about agile development in the abstract, but rather gives a no-nonsense explanation of how to practice it well.

Teaching by Example

Uncle Bob has no hesitation about diving into code to make his points. While there is plenty of exposition, including a lengthy and invaluable section on heuristics for writing clean code, all of the books major assertions are backed up by several lengthy sections of code.

Clean Code follows a repeated pattern: an explanation of a bad coding practice, and example of code that follows that practice, and then examples of how Uncle Bob would iterate on that code until it is clean. This pattern makes the reading dense, but by showing his assertions in practice Uncle Bob both educates the reader on best practices and forestalls any objections to his assertions.

I Hope You Know Java

One of the things that made the book less useful for me is that all of the code examples are written in Java. Java is one of the most widely known coding languages out there, so it's no surprise, but I was somewhat disappointed that I was not forewarned that I would be digging through code I only vaguely understood. And while I can't speak for the printed versions, the kindle version lacked syntax highlighting, which could have made the code more readable even though I'm not familiar with Java.

While most of the book provides insight into general coding best practices, there are whole sections of the book dedicated specifically to Java implementations. Uncle Bob is also a strong advocate of Object Oriented Programming, and much of his suggestions are premised on that coding style. Programmers who prefer Functional Programming may still find Clean Code useful, but certainly less valuable.

If you want to level up your coding skills, this book is worth the read. While I'm still working on the craft of coding, Uncle Bob did a great job displaying what I should be aiming for and how to get there.