Thursday, February 26, 2009

Book Review: Clean Code

Clean Code by Robert C. Martin, ISBN 0132350882

Here’s a rhetorical question: Should you work hard to ensure your software code is readable, well-structured, uncluttered with useless or flat-out wrong information, and is well designed? Rhetorical question #2: Should you spend time polishing code when you modify or maintain it to ensure you’re improving the code you wrote earlier?

“Uncle Bob” Martin’s Clean Code is a book full of sage advice on being able to deal with both those questions. The book’s broken into three separate sections: Good craftsmanship principles, case studies of refactoring code, and smells/heuristics in existing code. There’s also an appendix on dealing with concurrency.

Martin starts out with a frank example of how poorly written and maintained code can torpedo an entire company. A product that Martin and many others used in the late ‘80s began to lag with its release cycles, and bugs weren’t being fixed in subsequent releases. The situation worsened, sales vanished, and the company eventually closed its doors. Martin recounts meeting one of the company’s employees years later – and finding out that an unmaintainable codebase was the cause of all the woes.

Clean Code is intended to help you avoid such a mess.

The initial section covers such fundamental principles as naming conventions, function/method design and layout, use of comments, and a passle of chapters on design principles. There’s a great wealth of things to get your mind rolling in this section, and you get a number of different voices/viewpoints as Martin brings in colleagues from ObjectMentor to write various chapters.

The second section is made up of three refactoring walkthroughs. Martin shows the initial condition of each example (all real-world software), then goes into great detail of the small changes he makes to apply the principles from the first section. These three chapters are outstanding examples of putting the principles from the first section to work. Additionally, Martin’s writing style makes it seem that you’re sitting down with him for a pairing session as you read. Normally I hate these over-the-shoulder discussions because authors usually fail and end up with a sappy, overly chatty example. Martin’s succeeded at this before as well with his example of a pairing session in Agile Principles, Patterns, and Practices in C#, another book you should run out and buy.

The final section is one chapter with a large number of smells and heuristics you can apply as you’re writing and refactoring your code. Each item is concise and to the point, some with terse but beautiful example code.

The term software craftsmanship is generating a tremendous amount of discussion on blogs, articles, and podcasts. If you care at all about improving your skills and being a true craftsman, then you need to read this book.

Also, if you don’t follow “Uncle Bob” Martin on Twitter, you should. You’ll get a passle of insightful bits on software craftsmanship, find useful tools like Uladoo, and get some passionate views on politics and life mixed in with all that.


Anonymous said...

Jim, Thanks for the review. It doesn't sound like the book would be optimal for a book-club atmosphere but I wanted to gauge your thoughts on that.

Anonymous said...

I would love to follow @unclebobmartin, but political tweeting should not be encouraged. Tweets are not the place for politics, really, come on, you get 140 chars to talk about a trillion dollar stimulus. I just did the math, that's ~7billion dollars per character, spend them wisely.

Anonymous said...

Hi Jim, I'd like to hear about what you liked / didn't like. I read the book and thought that the chapter on functions was particularly good.

Subscribe (RSS)

The Leadership Journey