We had a decent turn out to discuss Beautiful Code edited by Andy Oram. Besides me there was Graham, Tom, Steven, David, Victoria and John, of whom about half of us had read some of the book.
The book is a collection of articles and so I’d just dipped in and read whatever chapters I’d fancied, whereas some of the others had started from the start and read them in order, although no-one completed all 500+ pages.
Overall, I found it to be a bit of a mixed bag. There were some interesting chapters and some rather less so. I also thought that quite often the link to ‘beautiful code’ was a little tenuous. Often it seemed like the concept behind the code was elegant while the code itself was a little on the ugly side. Graham agreed and said that he had expected the articles to be more inspirational. David pointed to the chapter on Code Generation (Chapter 8.) as one where the code got pretty gnarly while the idea behind it was pretty.
We looked at the different chapters in a bit of a random order, so here are some of what was said about each:
David liked the chapter on Haskell and Software Transactional Memory (Chapter 24). The idea is that your code is split up into code that is guaranteed to be side-effect free and code that is not. The transactional memory is implemented in an optimistic locking style. Since you are using the side-effect free code, if you hit a conflict you simply retry. The beauty came from the way the language kept the two different types of code apart. I liked it too, but when it got to the “Santa Claus” problem I found that there was too much new stuff for a Haskell newbie such as myself.
I liked the chapter on “Beautiful Tests” (Chapter 7). The code was simple, but it showed that finding bugs in the code was actually very hard. Graham thought that it highlighted the difficulty in proving the absence of defects. It introduced the idea of test theories to help you think of circumstances that your tests don’t yet cover. An interesting metaphor was that tests are like sportsmen in that they work best in teams with each one looking after a different area.
A chapter that Graham liked was “The most beautiful code I never wrote” by Jon Bentley (Chapter 3). Unfortunately I tried to read this in bed and fell asleep. David said it reminded him of a lecture from his student days and that it had had a similar effect on him then. He liked the clever algorithms in Chapter 10 “The quest for an accelerated population count” and said that he was glad that someone had written these things down.
Michael Feather’s chapter on the design of FIT (Chapter 6) was one I liked because it showed some code that didn’t follow the traditional rules of API design but ended up with a small, clean set of classes that do what is required of them.
Last but not least, Chapter 11 “Secure Communication: The technology of Freedom” got a bit of a thumbs down. David branded it as being like someones blog on what they did on their holidays. This was the only chapter John had looked at (on the bus coming to the pub) and it had not left a good impression.
I’m sure I missed lots of good conversations, but the book is such a mixture of things that the conversation did tend to move around quite swiftly. If I missed your favourite chapter out, give it a mention in the comments…..