One of the wonderful things about working at MIT was that there was a lotof code sitting around that was not kept under lock and key, written bypretty smart hackers. So I read the ITS operating system. I read theimplementations of TECO and of Lisp. And the first pretty printer for Lisp,written by Bill Gosper. In fact I read them as a high-school student and thenproceeded to replicate some of that in my 1130 implementation.

I would not have been able to implement Lisp for an 1130 without havinghad access to existing implementations of Lisp on another computer. Iwouldn’t have known what to do. That was an important part of myeducation. Part of the problem that we face nowadays, now that softwarehas become valuable and most software of any size is commercial, is that wedon’t have a lot of examples of good code to read. The open sourcemovement has helped to rectify that to some extent. You can go in andread the source to Linux, if you want to. Reading the source to TeX was avaluable exercise just because it was a large body of well-thought-out, well-debuggedcode.

Seibel: I usually have the best luck reading code when I have a very specificneed to know how something works; what is your mindset reading aprogram like TeX?

Steele: Sometimes I’ve got a specific goal because I’m trying to solve aproblem. There have been exactly two times, I think, that I was not able tofix a bug in my TeX macros by reading The TeXbook and it was necessary togo ahead and read TeX: The Program to find out exactly how a featureworked. In each case I was able to find my answer in 15 minutes becauseTeX: The Program is so well documented and cross-referenced. That, initself, is an eye-opener—the fact that a program can be so organized and sodocumented, so indexed, that you can find something quickly.

The other thing I learned from it is how a master programmer organizesdata structures, how he organizes the code so as to make it easier to read.Knuth carefully laid out TeX: The Program so you could almost read it as anovel or something. You could read it in a linear pass. You’d probably wantto do some jumping back and forth as you encountered various things. Ofcourse, it was an enormous amount of work on his part, which is why veryfew programs have been done that way.

Seibel: And when you get to the end, what are you going to take away?

Steele: I’ll have a pretty good idea of how it’s organized and I may havecome away with some ideas about how to organize my own code better. Idon’t think I’ll ever be able to write in the style of Knuth any more than Icould write in the style of Faulkner or Hemingway. Nevertheless, havingread novels by those writers will influence my own thinking about Englishstyle a little bit. Maybe I’ll make a conscious decision not to write likeHemingway for some reason or another. It’s a valuable experience. Not tomention just the enjoyment of going through a well-written novel or a wellwrittenpiece of code.

Seibel: Have you ever written literate programs?

Steele: Not in nearly the disciplined way that Knuth has. It has influencedmy style in that I think about those issues—I will often actually write aparagraph of prose before beginning to write a subroutine. But I don’t do itin nearly as disciplined a style. And sometimes I wonder whether he does,either, when he’s doing exploratory programming before he readies it upfor publication. I don’t know what his process looks like there.

Seibel: So you’ve tried it but it didn’t strike you as something that madeprogramming much more productive or enjoyable?

Steele: In part I didn’t feel like doing a lot of tool building for myself. Thetools he had built were organized around Pascal and then C. Pascal I couldsee but I was quite aware of the flaws in C and I wasn’t sure that usingliterate programming tools would suffice to overcome them. If he had builtliterate programming tools for Common Lisp I might have jumped over tothem much more quickly.

Seibel: Leaving aside literate programs and back to reading code, do youfind that you can read usually well-written programs from beginning to end?Or is it always a hypertext that you have to find your way through?

Steele: I don’t necessarily object to hypertext. But I think if a program iswell written, there will be something about its structure that will guide meto various parts of it in an order that will make some kind of sense. Youknow, it’s not just what the program does—there’s a story. There’s a storyabout how the program is organized, there’s a story about the context inwhich the program is expected to operate. And one would hope that therewill be something about the program, whether it’s block comments at thestart of each routine or an overview document that comes separately orjust choices of variable names that will somehow convey those stories toyou. And one would hope that a good programmer, a really goodprogrammer, will have given thought to conveying those stories in additionto the story of what the program actually does.

Seibel: What code have you read most recently just for fun?

Steele: It’s hard to find good code that’s worth reading. We haven’tdeveloped a body of accepted literature that says, “This is great code;everybody should read this.” So it tends to be one-page snippets, often inpapers, rather than chunks of code out of existing stuff. Probably the codeI’ve read most recently is the stuff that my own team has been producing aspart of the Fortress implementation. And parts of the Java libraries.

Probably the last substantial body of code I read just for fun was written byGeorge Hart. He’s a mathematician, a specialist in polyhedra. And he has avery interesting piece of code that will generate and display complexpolyhedra using VRML within a browser. And so he’s got this enormousbody of JavaScript code that constructs VRML code and then feeds that tothe VRML displayer.

I decided to try to enhance it in various ways so I went in and read his codethoroughly. And then proceeded to try to make various enhancements to itand understand what was going on: try to make some somewhat funkierpolyhedra and so forth. I also managed to make several bad errors—therewas a relaxation algorithm that tries to spread out the vertexes of thepolyhedra to make it prettier and easier to display, and occasionally I’dintroduce mathematical instabilities which would cause grotesque things tohappen. Tremendous fun, and I was doing this purely for my own edification.That was probably six or seven years ago.

Seibel: How much did the reading and the modification intertwine? Canyou read sitting at a table with a printout or at a computer withoutexecuting it to see what happens if you twiddle that little bit there?

Steele: Well I did, in fact, print out the code on paper. I would sit at a deskand read it. And very often mark it up and make annotations and ask myselfquestions and things like that. And then I’d go back to the computer andstart typing in things and see how it behaved. And tracing it.

Seibel: In this case you wanted to modify it, so that’s what you did. Butcould you get some benefit or enjoyment out of just reading the code? Printit out, read it, maybe scribble some questions on it, and then put it down?

Steele: Yes. If I had stopped at that point, it would have been a worthwhileexercise, just having read the code. It taught me something about VRML; ittaught me something about JavaScript, which is that it doesn’t have as manyabstractions as I would like. The dynamic typing was a little bit too freeformfor my taste—in an object-oriented language.

Seibel: So let’s talk a little bit about designing software. You’re not codingas much these days as you used to, but how did you go about designing anew piece of software? Do you sit down at a computer and start coding ordo you sit with a pad of graph paper, or what?


Перейти на страницу:
Изменить размер шрифта: