There have been a few moments while reading that I've literally put my hand to my head and asked, "Why didn't I understand that already?!" Beautiful things are often like that: obvious once you can perceive them. Because of that beautiful things are often easy to discount: we tend to forget the things of greatest value and beauty because they are so obvious that we stop paying attention to them.
Things like the process by which food is made (nuclear energy production in the sun, hits our planet, a whole bunch of amazingly cool chemical reactions store that energy in these really complex machines that we call "living plants" that we can then eat because our bodies have found a way to release, and even re-store then re-release, said energy .. ATP is so cool!) because we are always eating it.
There are three things I try and do now and again to counteract this "jading through aging" effect, though I often forget to keep up the practice:
- Listen to others with deeper understanding talk about these things, as they'll give us new "ah-ha!" moments
- Explain something I take for granted to someone who doesn't: the difficulty of doing that, and the feedback from the other person help remind me just how crazy cool things are
- Experience things differently; e.g. for food: eat an entire meal with just fingers and no utensils, even if its messy.. in fact, better if it's messy. Touching the food lets me experience it with more information than I usually do when using a fork and knife. This seems to help.
Anyways.. this wasn't meant to be a blog posting about "how Aaron tries to keep in mind the wonder of life's mysteries" but about that book on beautiful code. So ... one of those "ah-ha!" moments for me was when reading Jon Bentleys' chapter called "The Most Beautiful Code I Never Wrote". In it he performs an interesting, lucid and very intuitive analysis of the quicksort algorithm by starting with a very straightforward impmlementation of it and then paring it down further and further to arrive finally at a description of its runtime that also provides the answer to that question.
Very nicely done.
But it was the "A Bonus Analysis" section tucked right near the end of the chapter that blew me away. Jon quoted Goethe: "architecture is frozen music". I love that quote. =) Then he rephreased it for software: 'In exactly that sense, I assert that "data structures are frozen algorithms."'. Wow. I'd never thought about it that way ... the idea is so fundamental, simple and beautiful.
Then he goes on to show with one diagram and a couple hundred words how a binary search tree is actually the quicksort algorithm using an ideal partitioning method.
How the hell did I never see this before? It simultaneously made me feel very humbled (a kind way of saying, "I felt rather stupid" ;) and filled with the awe of its beauty: it's a wonderful idea that data structures are actually algorithms (which we've probably already seen before) in a "frozen" representation. It's not that we construct them, traverse them, modify them, etc using algorithms: they are the algorithms, just as architecture is music. One wouldn't literally use quicksort to traverse or create a binary tree, but it's also obvious that the same number and the same set of comparisons are made in both a quicksort and in creating a binary tree. They are the same thing described in different ways (structure versus action).
Ok, maybe this was already glaringly obvious to everyone else (it's so obvious now that I write this that I feel slightly silly gushing about it so ;) but it was a nice little "ah-ha!" moment for me. It brought back a recollection of that feeling of new enlightenment that was easier to achieve as a child, when everything is new and therefore beautiful.
I'll leave with two more quotes from the end of that chapter:
Refering to the examples Jon had written in the chapter, none of which he'd compiled, quite purposefully, even those some where decades old, he said: "I hope that the deep beauty I find in them will be unmarred by superficial blemishes." Amen!
And finally ... "Beauty has many sources." =)

6 comments:
Code ala Tufte. You almost want to print it and hang it on your wall :)
There's a google tech talk by Jon Bentley on the same subjects. Recommended.
I've heard that the rest of the book is fairly uneven quality, interested to hear your thoughts on other chapters.
There's a Beautiful Teams book in the works too I think.
I enjoyed reading your philosophical musings! I completely agree that experiencing the thing in itself, like the food or the local community, is of great value.
AAAH! data structures are frozen algorithms! Your "ah-ha!" moment has propagated.
If you can see beauty in creation, then imagine the beauty in the Creator!
Post a Comment