July 28, 2013

Clean Code

by Robert C. Martic

An interesting and readable tutorial about current code aesthetics, this book is the software engineer’s Strunk and White.

Again, it’s remarkable how greatly style has changed within the past decade. In the 20th century, you were supposed to write comments. Now, we don’t: if the code is so unclear as to need a comment, it needs to be fixed. Martin does devote an entire chapter to comments, in a quaint gesture toward the elegant weapons of a more civilized age, but it feels out of place.

More interestingly, Martin is an extreme proponent of what I call the tiny methods style. He does not hesitate to make code longer — even substantially longer — in order to break up large methods. A proper method, to Martin, is one you can see at a glance.

Clean Code begins with a pleasant chapter in which the luminaries of the Agile Era propound their vision of clean code. This is interesting and useful and the accompanying portrait sketches are great: for the people I know, the likenesses are terrific. Readers will note the preponderance of beards, and it’s interesting to learn that jUnit originated as a diversion on a plane. The rest of the book’s illustrations are juvenile puns executed by an artist who has not quite mastered the anatomy of the hand, and they add little. The code examples are clean but a few blunders creep into the text. You generally don’t see this from Addison-Wesley or O’Reilly; Prentice-Hall should have caught them.