Snippets of Beautiful Code

Leaving out the obviously pedagogical works; this is for fun.  How much can you learn from a few lines of code?

I read Kernighan and Plauger’s book Software Tools nearly 30 years ago; it was a wonderful introduction to clear, crisp programming and mid-level design, and I’ve rarely seen books as compact or (I think the right word is) humble.  It covered a lot of territory in just a few hundred pages, all the way from simple searches to a compiler/translator, and most of the tools were useful.  It was clear that while the authors knew what they were doing, they weren’t trying to hit you over the head with an agenda other than keepings things small and simple, a refreshing change from many of todays’ “Wham! Object! Oriented! Programming! With! Freebles! Is! The! One! True! Way! WhamWhamWham!”

A few other snippet-like books I’ve enjoyed have included Knuth’s source code for TeX (though frankly reading web-style code gets tiresome after a while), Jon Benley’s Programming Pearls series (less for the code than the pragmatic reasoning), and the three volumes of the ACM’s History of Programming Languages conferences (seeing the thought process behind your favorite languages — and the horrible mistakes either avoided or committed — is quite interesting).  Programmers at Work was fun, but badly needs an update and it wasn’t heavy on technical details.  Skiena’s The Algorithm Design Manual sounds dry, but has some nice commentary and good war stories (he actually calls ’em war stories — anyone who’s been in the trenches knows that CS is really a battle between good and evil, right?).

O’Reilly has just published Beautiful Code (ed. by Oram and Wilson), which is a collection of thirty or so chapters by various pretty good engineers describing quite pretty hunks of code and design.  I’m four chapters into it and can’t put it down; the description of how Subversion does delta-tree transmission is so obvious that it’s a wonder anyone could have done it a different way.  There’s stuff here all the way from how Python does hash tables [which I don’t like, though I guess it is pretty] to a discussion of design defects [defects are pretty? yes!] in the Solaris kernel.


I spent a few days last week learning (that is, doing something real for the first time with) Lua.  It’s a fine, pretty, small language with no illusions of grandeur; it gets the job done and stays out of the way.  [I wish it had less free scoping, but a perl script fixed that].

Some people lament the proliferation of small languages.  I’m frankly of the opinion that you can’t have too many, and if the whole world was Java or C# we’d be in the same boat as if we were all plugging away at “perfectly good FORTRAN.”  Though debuggers are nice . . .


Author: landon

My mom thinks I'm in high tech.

Leave a Reply

Your email address will not be published. Required fields are marked *