Good stuff

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.

This entry was posted in Rantage. Bookmark the permalink.

13 Responses to Good stuff

  1. Anonymous says:

    “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.”

    Funny, we were doing the same thing at HP, to patch the 49 and later calcs… 🙂

  2. ron says:

    Nice post – Code is poetry 😉
    Although I’m still a coding noob, I think assembly language is teaching a lot about how to strip down and rearrange code snippets to gain more efficiency.

    The most impressive code to me is rob hubbard’s music routine. May be pretty mainstream nowadays..

  3. Jack Hughes says:

    The CLIPS code written at NASA was/is a great example of how to write C code. I learnt a lot from it.

  4. SoLinkable says:

    “What’s the most interesting code you’ve read?” – This is an incredible interview question. I think this would really show you who WANTS to code rather than simply who CAN code. Good stuff. I thinkn I’m going to pass this along to my boss…

  5. greywulf says:

    Amen to all that.

    For me, it was the early Linux kernel i/o code. Sure, it was kludgy in a lot of places, but you could tell it was put together with a lot of love.

  6. Sara Chipps says:

    It’s funny, as a younger programmer and someone who, sadly, will never experience that type of environment there is a bit of love in my heart for you guys. Yes, software is a completely different animal now, we have good coding “styles” and “standards”, the right way and the wrong way and techniques a plenty … these things are hammered into us, it’s hard to be truely unique, but I guess that’s the fun part of the challange. However, gone are the days of cool hacks and discovering wild new ways to do things and just going to town on what inspires you. I envy you guys quite a bit for having that freedom, and enjoying being the pseudo-pioneers of this now well documented field. Definitely an experience to treasure, I raise my glass.

  7. CiaranG says:

    The most “interesting” code I’ve ever seen is from the PC version of the Star Wars coin-op. Interesting in the sense that having revisited it a couple of times recently (e.g. ), I’m shocked we managed to even understand it while it was fresh in our minds.

    In my defence, it was hastily converted to x86 from the Z80 version, and that in itself was done it what now seems like an incredible 8 weeks.

    So not the Mark XIV shovel – more like the rusty old one you found in the back of the shed, that once upon a time, you’re sure, was very effective.

    I bring this up because, apart from being “interesting” in a different way to what you had in mind, I suspect that the machine I had sat next to my desk while developing it had the same coin-op mechanism you mentioned.

  8. justinhj says:

    Some code that came to mind was the state graph search code in Peter Norvigs PAIP… it gradually refines search from basic breadth and depth first, to beam search, IDA* and so on. The remarkable thing is how little the code changes on each iteration, with the basic structure of search being so nicely abstracted from the beginning.

  9. Ted says:

    Well back in my day…

    I fondly remember the early 80s when I was able to code first for myself and then for my employer. What mattered at the end of the day was how I “felt” about the code that I had written. If it didn’t feel right I was up late into the night doing a rewrite, sometimes from scratch.

    But it was a great feeling I haven’t been able to recapture in a long time. But I will get back there soon.

  10. j h woodyatt says:

    I’m afraid of what this will say about my, but the most interesting code I’ve seen is Dan Bernstein’s C libraries and implementations of DNS and SMTP. It’s very terse. It has almost no comments. The variable and type names are short and often single letters. This style drives a lot of people nuts. I, on the other hand, can only admire it. It is code that requires no comments. It just works.

  11. Pingback: Learning Perl by Reading and Stealing Code from CPAN… « Learning Lisp

  12. fogus says:

    I second CLIPS as a great example of finely crafted C code. It’s a highly complex system written in such a way that is comprehensible. Recommended reading. 🙂


  13. I was going to post a comprehensive reply, but I got distracted in talking with other people about this. So, some of the most interesting code I’ve read: the code in the Lions book, Sedgewick’s code in Algorithms in C, a lot of the code in TAOCP, Norvig’s tiny Python spell-corrector, the sequence of interpreters in Essentials of Programming Languages, the nightmare that is, the mind-blowing total system that is F-83 (why did Forth not take over in the 1980s? I don’t understand), Darius Bacon’s “ichbins” (everything I’ve read of his is really clear), and qmail. More details later, maybe. Thanks for the recommendations, everyone!

Leave a Reply

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