Book Review: Clean Code
I just finished my March book from my 2010 developer-oriented book reading list, so I thought I would share some thoughts on Clean Code by (Uncle) Bob Martin before moving on to my April book, Real World Functional Programming: With Examples in F# and C#.
Rating -
(out of 5)
Prerequisites – The code samples in the book are in Java, so if you’re not a Java developer it’s probably worth going through a quick tutorial first. Most of the examples rely on low level coding constructs, so you can skip familiarizing yourself with the Java APIs and focus on just the basic language syntax and the common data structures. A quick 10 minute read of this high level language comparison will probably be sufficient for most C# developers.
The Good
- Conceptually Cohesive – Choosing “Clean Code” as a title and topic of a book was somewhat risky because it is such an intrinsically nebulous concept. However, Bob Martin overcomes these hurdles by defining “clean” as any practice that makes code easier to understand. Just like usability experts carved a respectable science out of UI design, this book adds objective weight to the topic by examining seemingly subjective practices through a lens of measurable efficiency. For example, “code noise”, such as redundant comments, is bad because it causes unnecessary eye movements and scrolling. Likewise, descriptive names, short methods, and small classes are all preferable because they minimize the short-term memory requirements of the reader and thus increase the speed of comprehension as well as the capacity to discover logic flaws.
- Thought Process Over Rules – Although the catalog of code smells and heuristics that Bob Martin provides towards the end of the book are helpful, his ability to recreate his thought process while refactoring code is definitely one of the more valuable parts of the book. Context is everything and learning rules without fully understanding when it is appropriate to apply them will almost always cause more harm than good (e.g. design patterns). The way the author sometimes changes his mind and even reverses himself as the code takes shape is a superb teaching technique because it models how to fully analyze the context. There were several times where I disagreed with his final solution, yet still felt satisfied that I had learned new ways to think more critically about the choices I was making.
- Code-Centric – Like rules without context, abstract concepts without extensive grounding in concrete examples are worse than useless. Another strength of the book is that it is code-heavy without ever being repetitive or wasting time on obvious examples.
The Bad
- Length of Case Studies – Although I firmly agree with the code-centric approach the book takes, I think it was a mistake to chose such large code samples to refactor in the second half of the book. I might have been more patient with the constant page flipping and mental gymnastics involved in reconstructing how code had changed if I weren’t already so used to using tools like Resharper, Subversion, Beyond Compare, and Fisheye. At the end of the later chapters I felt the same frustration I feel anytime I’m forced to revert to a manual task that provides a fraction of the value for a lot more effort. I just don’t think books are the appropriate medium for these types of large code reviews.
- Several Extraneous Chapters – There were several chapters in the middle of the book that seemed out of place and thus distracted from the main theme. For example, the chapter and rather large supplemental appendix section on concurrency devoted too much time to multi-threading fundamentals rather than focusing on the main them of how to increase readability. Likewise, several other chapters covered topics that were not directly relevant or were dealt with at a level that was too superficial. It reminded me of methods that Uncle Bob criticized in the book for mixing levels of abstraction. It would have been better if they had just been cut out of the book.
Conclusion – I struggled when trying to come up with an overall rating for this book because I absolutely loved the first hundred pages of the book but was decidedly less excited about the rest of it. Ultimately, I gave it three stars because I think it deals with a really important topic and does it quite well for a sizable part of the book.
If you are either a junior level developer or else haven’t read many other books about refactoring (e.g. Martin Fowler’s classic Refactoring), then I would consider this book a must-read and would definitely buy it. Otherwise, you’re probably better off just borrowing it and only reading the first one hundred pages or so.
Popularity: 1% [?]
Comments(1)
I was just debating whether I should try to sweet talk my wife and bribe my boss into letting me go to the 



