I just got finished reading an interesting book call Beautiful Code. The editors sought out a number of developers and asked them to author chapters about what they felt was the most beautiful code they had seen. Karl Fogel, of Subversion fame, had a chapter about Subversion’s delta editor (congrats to Karl!). There were some interesting stories about some optimization techniques, testing, and even style. But that one that stood out the most was the final chapter of the book: Writing Programs for “The Book” by Brian Hayes. That chapter wholly lined up with my vision of beautiful code. In the chapter, Brian states:
...a program must be more than just correct; it must also be lucid, elegant, concise, even witty
I couldn’t agree more. Throughout the chapter, he talks about a small piece of code that felt dirty… that there was a better way, but he just couldn’t see it. The story took you over several iterations of this small chunk of code, which seemed to get closer to a solution, yet still seemed so far. Until one day, when Brian read a paper that had the one nugget that he had been looking for. In the end, the answer turned out to be short, sweet, sensible, and had no special cases… it was beautiful. That story alone was worth the purchase price.
Those of us who love to write software often view it as a work of art. I think the editors where right on in attempting to collect some of those works, and I hope this is the first of a long series of books to follow.