Review of "Beautiful Code"

Editors: Andy Oram, Greg Wilson
Publisher: O'Reilly (1st ed. June 2007)
Review by: Cosimo
Rating: ****-
Date: 2008/05/01
Cover of the book

60" summary

I found this book really enjoyable and interesting. There are 33 chapters, each by a different author, mostly really famous people, each with his own concept of "beautiful code", but nevertheless a great (but sometimes heavy) reading.

Review

This book is probably not like what you expect it to be.

I was curious to read some of the existing reviews about it, and they turned to be really interesting, especially the negative ones. Seems like somebody didn't find step-by-step instructions to produce beautiful code. Of course not.

This is a kind of book that tries to show the insight, the original thinking and programming process of the various authors. It's not a "Beautiful code for dummies".

And as such, it is a rather "fragmented" book. Each chapter is from a different author, so don't expect a common structure or anything. The common topic is the author's own idea of "beautiful code", being that performance, simplicity, elegance, insight, or whatever.

The authors

There's an astonishing quantity of programming stars, starting with the first chapter, "A Regular expression matcher" by Brian Kernighan, going through Jon Bentley, Charles Petzold, Lincoln Stein, Greg Kroah Hartman, Simon Peyton Jones, Douglas Crockford, Yukihiro Matsumoto, and many others.

Topics in the book

There are plenty, from low to high level. Some examples:

Also several different programming languages, from C, to Perl, Haskell, PHP, Python, LISP, even pseudo-code.

Best chapters

I read this book some time ago, so I don't remember perfectly every detail. But this can be good, because the things that stick into mind after a long time are probably the best ones... :)

"The most beautiful code I never wrote" by Jon Bentley

Bentley dissects his version of the classic quicksort algorithm, and shows how to take little steps to improve a working version of a program. He also explains, in a not-too-formal way, how to analyze algorithms behaviour and performance.

"Beautiful tests" by Alberto Savoia

Test driven development and JUnit testing. Savoia takes a binary search implementation in Java and shows how to test it properly with edge cases, smoke testing, random data and automated performance testing.

"Another level of indirection" by Diomidis Spinellis

"All computer science problems can be solved with another level of indirection". This is a famous quote. This chapter shows how this principle is applied in the FreeBSD virtual filesystem layer.

"A spoonful of sewage" by Bryan Cantrill

Detailed description of how the author helped fix a thread deadlock bug in the soon-to-be-released Solaris 8 kernel. An interesting reading for a complex and tricky problem.

'Beautiful debugging" by Andreas Zeller

Excellent! Worth the whole book. Zeller is one of the current developers of ddd, the Data Display Debugger. He shows how he debugged his own debugger with a general purpose, automated "brute-force" debugging process, the Delta Debugging algorithm.

"When a button is all that connects you to the world" by Arun Mehta

The birth and development of eLocutor, a unique user interface software thought for professor Stephen Hawking.

"Code in motion" by Laura Wingerd and Christopher Seiwald

This is one (maybe the only one) that talks about beautiful code in the sense of source code text. How to write good code from a stylistic point of view. Comes from the experience of the authors as developers of DiffMerge, a component of Perforce SCM.

You can also read this full chapter on Perforce web site.

... and others ...

There are really many more, and in fact, every chapter is well worth reading.

My opinion on the book

I really like this book approach. It's definitely not always an easy read. And be prepared, because it's a full 600 pages book...

Each author tells about his own idea of beautiful code, and shows the steps he went through to reach the final result. In other cases, the author describes the architecture of that particular system from a high-level point of view.
In any case, it is this kind of "enlightening" that can be valuable for programmers. It's more about ideas than code.

Conclusions

A great book. Every now and then I come back to read again some particularly brilliant chapter. It's like buying a graphics book, you can always look at it to find inspiration.

Pros

Cons