Talking about code

If you read this blog and haven’t yet listened to last week’s episode of the Generational podcast, you owe it to yourself to bring it to the top of your queue. Gabe’s guests were Brett Terpstra and Rob Trew1 and the topic was programming. It wasn’t about languages or text editors or coding styles or tips and tricks, although all those topics were touched on. Mostly, it was about the pleasures of amateur programming,2 and I enjoyed every second of it. I felt as if I were part of the discussion, nodding in agreement most of the time, occasionally wanting to butt in with a respectful disagreement.

One disagreement came when Brett mentioned a Pascal course he took. Brett’s in very good company in his dislike of Pascal, but I can’t help but have fond memories of the language. It was in a Pascal course my senior year of college that I really learned about programming.

I had, of course, had a Fortran class as a freshman (it was still written FORTRAN back then), but so much of the time was spent on learning ephemera: using a keypunch machine, submitting a job, keeping the JCL cards in order, indenting to the 7th column, learning the device numbers. There wasn’t enough time to learn all that shit and learn programming, too.3

I took the Pascal course the first semester of my senior year because I needed a technical elective outside the civil engineering department, and I had a vague sense that knowing how to program would be important if I wanted to do high end structural analysis. The instructor was Sam Kamin, who I heard was new to the CS department. Professor Kamin retired just a few months ago, and the article announcing it says he was with the UIUC CS department for 33 years. Given that the class I took with him was in the fall of 1980, it may well have been the first course he taught.

His inexperience might explain the pace of the course. He just didn’t know that you can’t take a class of non-CS majors from a standing start and have them end up writing a working text editor for their final project. We in the class didn’t know that, either, so we did it. I don’t think I’ve ever learned so much in such a short period.

If you don’t think writing a text editor is a big deal, let me remind you that we had no libraries to lean on and that standard Pascal at the time had no string variables. We had to build up all the infrastructure ourselves.4 I don’t want to make it sound like we each built a BBEdit, but at the end of the course I had a serviceable line editor that I’d written myself. Not nearly as many features as the editor I used to write it—the Illinois Central Editor, ICE, running on a CDC Cyber 175—but a usable subset.

What made the course great was its emphasis on structured programming and data structures. Structured programming was a big change from the Fortran course, where GOTOs were still the order of the day. We had learned about subroutines, of course, but you could still get an A in Fortran by handing in spaghetti code that worked. Prof. Kamin was having none of that. In every assignment, the main program was to be nothing more than calls to a few procedures to handle input, processing, and output. Those procedures were, in turn, to call other procedures and functions.5 No deep nesting of branches or loops.

It was data structures, though, that were the real revelation. Apart from arrays, there were no data structures to speak of in Fortran,6 so being able to define my own data types and put them together into more complicated types seemed like wizardry. And pointers! First, pointers to the built-in types, then pointers to the types we created. As you can probably guess, the editors we wrote used doubly-linked lists7 so we could maneuver through a file and insert and delete text with ease.

Ultimately, what that class gave me was not a knowledge of Pascal, but a solid grounding in the rudiments of programming—enough to be able to pick up other languages quickly8 because I could see through their syntax to the fundamentals underneath.

As a brief aside, I’d say that Leo Brodie’s two Forth books, Starting Forth and Thinking Forth, both of which I read in grad school, have had almost as much influence on how I think about programming. Old Mac hands will remember that Forth was one of first languages available for the Mac (initially, it had to be programmed on a Lisa), and I stumbled onto those books as I was looking for a way to program my new Fat Mac. Traditional Forth is even more strict about modularizing code than Prof. Kamin was, so I was forced to think hard about what I wanted my programs to do and how to divide those tasks up in the clearest and most efficient way.

Those few of you who actually read the code I post here may be smiling, because the programs I write now certainly don’t have functions for every subtask. In fact, most of my scripts have no functions at all. But I still think in terms of subtasks and separate my code, through comments and spacing, into sections for each part of the job. Prof. Kamin would probably think otherwise, but I believe I’m still following his teaching.

  1. As an American, I’m hardly an expert on British accents, but to my ears, Rob is the archetype of RP. He makes Stephen Fry sound Scouse. 

  2. Brett writes code for a living, of course, but he’s best known for the stuff he writes for fun. 

  3. This is the way it is with all topics, I think. You don’t really learn until your second course in a subject, where you use the material you were scrambling to keep up with in the first course. I didn’t, for example, really learn statics in my statics class; I learned it in the strength of materials class the following semester. 

  4. Uphill both ways. Stone knives and bearskins. Like an animal. 

  5. Unlike every other language I can think of, Pascal distinguishes between subroutines that return a value (functions) and those that don’t (procedures). Not practical for a professional language, I suppose, but a useful distinction in a teaching language. 

  6. You could use arrays like a poor man’s data structure if you were willing to do all the bookkeeping. COMMON blocks could be divvied up into a structure-like system, too, but we didn’t cover COMMON blocks in that first programming course and I had to learn about them on the street. 

  7. I often wonder how many people who see a reference to “linked list” entries in blogs (like Daring Fireball, to give the most prominent example) realize that that’s a pun. 

  8. Not Smalltalk. That still looks like gibberish to me, maybe because my formal education predated the rise of object-oriented programming.