When was the last time you looked at code someone else wrote? (Debugging doens't count!) When did you actually study it to learn from it? Perhaps even ponder over its beauty?
It's surprising how uncommon it is in our industry to look at existing code just to learn from it. In almost any other engineering or art field, people constantly study the results of their peers. Books on architecture are a great example. What makes a certain design so beautiful or effective? Can I learn something from it to make me a better engineer? I feel we would benefit as an industry if we would collectively take a little more time to reflect and study. We should ask ourselves those question more often, and allocate study time for it occasionally.
Last week, I ordered the book Beautiful Code, by Greg Wilson and Andy Oram. I would recommend this book to any fellow professional programmer. (All of the book's proceeds go to Amnesty International.)
The book's concept is simple: each of the 33 chapters is written by a well-respected professional programmer who answers the question: "What is the most beautiful code you've ever seen?" after which they discuss elaborately why they think it's beautiful.
Beauty, as it turns out, comes in many shapes and forms. The topics in the book vary from an elegant algorithm, to a design that lets all the surrounding puzzle pieces fall into place perfectly. From the cleverness of code generators, to the expressiveness of a language construct.
Naturally, some chapters have been more interesting than others. But all of them have left me with either:
- a deep admiration for an elegant solution or cleverness;
- an interesting perspective on good design;
- an appreciation of seemingly banal things, or things I previously did not find beauty in;
- insight into how to articulate why exactly something is beautiful (how meta)