Clean Code: A Handbook of Agile Software Craftmanship by Robert C Martin
Publisher: Prentice Hall
Over the past 10 years, I've learned a lot from Robert C. Martin's writings. His previous book was a rewarding read and I had high expectations on Clean Code. It covers a vitally important area: the quality of our code matters. Any book that manages to teach us how to develop clean code is mandatory reading in my world. Unfortunately, I cannot put Clean Code in that category.
If you're programming in a language that doesn't limit your creativity to message-passing object-orientation, isn't statically typed, and doesn't go by the name of Java, then this book is of little use. Obviously, fundamental topics like naming, cohesion, and abstraction transcend Java. The chapters covering those topics unfortunately do not; the bulk of the writing addresses problems either inherent in the Java language or problems that simply do not exist in other languages or paradigms. The authors never acknowledge this. Worse, due to all accidental complexity of Java, it's simply a bad choice for communicating and teaching coding skills.
So, the scope of the book is more narrow than you would expect from the title or the back cover. And even if you consider it as a pure Java book, it has some serious limitations. I'm a big fan of Michael Feathers writings. Consequently, I had high expectations on his error handling chapter (a topic that gets way too little attention in most programming books). Sadly, the chapter didn't live up to my expectations. First of all, the chapter focuses almost exclusively on exception handling. And according to me: exceptions != error handling. Further, I believe Michael takes a too narrow and technical perspective. When it comes to error handling, you have to take the perspective of the user, which is what should drive your error handling strategy; not what's technically comfortable. Too much code in this book falls into the so common catch-and-log trap. I mean, seriously: logging an exception and continue may be a convenient way for you to debug your software but it will not impress me as a user of the application.
Clean Code is a team effort, although that fact is well-hidden on the book's cover. Robert C. Martin has only written a part of the book. The rest of the chapters are contributed by his Object Mentor colleagues. Like many other books where different authors contribute their own chapters, advices are repeated from chapter to chapter and the authors may even contradict each other. Some of the worst examples include class names ending with
- and this in a book stating the importance of good naming - others use checked exceptions despite a chapter recommending against their usage. At times it gets unintentionally funny; the stack presented as an example on high cohesion
a cohesion problem! Sure, it's a subtle one, but if you write a book called Clean Code I expect you to know and address issues like this.
If you've been following along, you could probably feel my disappointment with the book. Still, if you're a Java developer the book does have a lot to offer (parts of it may also be applicable to C# and other relatives). However, if you really want to improve your coding (and I'm talking about going beyond the seriously limited design space of Java) there are better books waiting to be read. I would definitely recommend spending time with SICP instead. A quarter century old, it's still the best example of truly great code I've come along; it's lessons and principles are timeless and applicable way beyond any contemporary technological fad.
Reviewed February 2009