Book Reviews

Clean Code: A Handbook of Agile Software Craftmanship by Robert C Martin

ISBN-13: 978-0-13-235088-4
Publisher: Prentice Hall
Pages: 464

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 limitations. I'm a big fan of Michael Feathers writings. And indeed, his chapter on error handling (a topic that gets way too little attention in most programming books) is well-written. I just wish he'd go deeper; The chapter focuses almost exclusively on exception handling and, according to me, exceptions != error handling. 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. Overall, too much code in this book falls into the so common catch-and-log trap. I mean, 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. Many programs take that somewhat narrow and technical perspective. There's definitely a need for an in-depth coverage of real error handling strategies.

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 Impl - 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 has 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