2009-02-28

Debugging and Science

I just finished reading Richard Feynman's collection of autobiographical sketches, "Surely You're Joking, Mr. Feynman" which is a lot of fun. He was a first-class kookball.

At one point Feynman talks about the moment when he figures something out: a new theory or insight or solution that neatly explains some previously mysterious behavior. And I recognized some of the feeling he was talking about, surprisingly enough, from the feeling of recently rooting out the causes of a years-old mandelbug at work.

This got me thinking about debugging, and programming, and complexity, and finally about mysteries...

As a high school student I was drawn to science, especially chemistry. But at some point I got discouraged: it seemed that all the interesting questions had already been answered. Now I'm old enough to realize that's far from true, but at least in my high school, science was approached as a very long series of answers, rather than questions. Experiments were basically mechanical: the results were all known ahead of time. No surprises and no mysteries. In fact, if an experiment's results were surprising, it was because the student made an error.

At the same time, I was taking programming classes (not to mention coding at home). And though I didn't think of it this way at the time, mysteries were popping up all the time. For example: I wrote a really simple polygon painting program (in MacPascal!) in one of my first CS classes. While working on it I'd get these really strange failure cases -- like, draw three triangles in a row and then hover the mouse for three seconds in the lower right hand corner of the window, and half the screen turns black. Stuff like that. Mysterious! So of course I'd stay late at school to solve it, and in the end there was always an explanation, however silly.

I think that was a big part of the allure of programming for me: the way even a fairly simple set of instructions can behave in ways even their creator finds mysterious.

Now that I work professionally on this stuff, it's even better. The software I write is layered on top of a *lot* of software written by others, which is layered on top of still deeper software, which is layered on top of an operating system, also software. And it's all open source (except the stuff I work on directly, ahem... but anyway I have that source code) so I can actually explain *anything*, if I have the patience and skill to figure it out. Except that one time where it turned out to be random memory corruption in a bunk SIMM... but that wasn't fair. Anyway, the point is, this stuff is complicated! It's not nuclear physics, and the "laws of nature" one discovers while debugging a complicated system of software usually have no meaning outside that system. But still, there's this satisfaction: I solved it!

Anyway, putting two and two together: I love debugging complex software systems because the harder it is, the more satisfying it is to fully explain some behavior. If my high school science teachers had talked about, say, the protein folding problem, I might very well have ended up a theoretical chemist.