Saturday, May 02, 2009

Book — Clean Code by Robert C. Martin.

The review, after following the advice contained in the book: Read this book!


Ok, let's back off one step...

If you write code at all, then this book will be of use to you. If you write code as part of your day job, then it is essential reading.


Ok, let's back off a long way...

Every so often, a book comes along that codifies best practice in a way that manages to illuminate the path from where things are right now, to a better place that we'd rather be -- things like Fowler et al's Refactoring or the Gang of Four Design Patterns. This is one of those books. And if much of the material is the sort that seems obvious in hindsight -- well, that is the mark of a well written book, to make the concepts that clear.

Taking a series of real world examples -- open source projects with significant user bases, including FitNesse and JUnit -- a series of worked examples take us from good, or at least adequate, code, to a form which is better factored, and easier to read, with the steps along the way clearly marked. Yes, even some of Kent Beck's code is put under the microscope, and carefully polished that extra stage or two more.

The reader is cautioned that, without working long hours to follow these examples, this will be just another of those feel-good books. I don't quite agree -- spending just a little time to follow the transformations, and then reflecting on one's own outpourings should be enough to make this a feel-bad book. All the sins from obscurely named variables to sprawling functions that gaily mix abstraction levels, we've all done them (especially programming in FORTRAN on minicomputers with slow stacks and a rule of thumb that 1 call ~ 40 loc in terms of performance).

The maxim to take from the book is based on Baden-Powell's "Try and leave this world a little better than you found it", and owes to the same school of thought as "whenever you are in the garden, pull at least one weed". The meat of the book is in distinguishing what are the weeds from the intended crop.

So read it, understand the examples, and then refer to it often -- like the other titles mentioned, it is a reference work, and should become one of the most thumbed on your bookshelf.

Post a Comment