Enough ranting. I want to talk about code that I liked, and what I learned from it.
The first really good stuff I encountered — after a number of years of reading Byte and Dr. Dobbs — was the late 70’s “new wave” clique of Kernighan, Ritchie and Plauger. I inhaled K&R’s _The C Programming Language_ and soon after that, Kernighan and Plauger’s _Software Tools_ (the hair-on-your-chest RATFOR version). And, of course, John Lions’ commentary on Unix, pilfered in classic Lions’ Notes AT&T Trade Secret Violation Style at 8pm on the office xerox machine.
I’m convinced that early exposure to Pretty Good Stuff helped me out a lot in school. Most of the courses I took in college were like “Here’s an algorithm, go implement it,” without much exposure to exemplars of good style at all. I had the feeling that TA’s had to wade through ghastly piles of brick-like Pascal from other students, and that the TA’s rather liked the style of the projects I turned in.
The next Good Stuff I read was at Atari, and it was some of the best 6502 assembly language code I’ve ever seen. What this code did was control the coin mechanism on many of Atari’s arcade machines (Tempest and Battlezone at least). It handled a lot of security issues (I forget what kind of jiggering it was capable of detecting, but it was rather a lot) and many different variations of currency (including foreign denominations) and payment setup. And it had to get things correct, or a pissed-off user might smash the machine and burn it.
I read most of the source to Donald Knuth’s TeX. I have a love-hate relationship with literate programming. On the one hand I think it’s a neat way to present a program. But on the other, I’m just not into writing literature; most of the time I just need to bang out something that works pretty well and that won’t leave the next guy twisting in the breeze. Raising edifices of deathless prose is a lot of bloody hard work. We can’t all be Hemingway; some of us have to write about the local dog shows.
I don’t think I read anything at Apple that really captivated me; maybe the Newton kernel, or the NewtonScript interpreter. However, I did see another example of great low-level code; a number of departments had huge feet-long bound listings of the Macintosh ROMs, which were very well commented 68000 and 68020 assembly. Many lines of it had the initials of the engineers who had last touched them, and you could tell at a glance where the hot spots were. (Updates to the 68K-based Macintoshes were pretty horrendous, and we carried this tradition along to the Newton — basically, you’d hook parts of the system and insert logic, by hook or by crook, that fixed problems or added features. Where you couldn’t directly patch something you could usually arrange to redirect a return address somewhere above you or something. There were some world class clever programmers at Apple who could take someone else’s attempt at a patch — say, fifty bytes — and boil it down to a gnarly twelve byte knot of distilled evil genius. It’s wonderful to have people like that guarding your back on a project).
There’s a style of systems programming that I aspire to that might be described as “just enough to carry the story” — it’s like that very spare 70’s Unix style, but with a little more plot. As a young programmer I tended to put hooks and cute features into everything; stuff had to be full of bells and whistles and show-off a lot or it wasn’t fun to write. These days I try to do just what’s necessary in the most direct and clutter-free way than I can think of. Usually this takes a couple of passes; often it involves ripping junk out, and it always involves checking my ego at the door. I am nowhere near the level of some masters of the art that I work with, and I hope to grow up to be like them some day.
Sometimes I ask people that I’m interviewing, “What’s the most interesting code you’ve read?” It’s saddening how many people don’t even understand the question, like I’m asking a ditch-digger which shovel is his favorite. Occasionally, though, a light will come on in the other person’s eyes, and they’ll start talking about the really neat garbage collector they ran into a while ago, or the Mark XIV shovel with the tempered rivets, scalloped handle and semi-gloss finish. And you know you have met someone who enjoys seeing quality software, studies it, and maybe knows how to write it, too.