The Tao of Computing

Author’s note: This post is intended to introduce a larger section of the book (at least a chapter), not stand on its own.

Expert programmers have all had “ah-ha” moments where, all the sudden, several concepts that were all unclear crystalize into one revelation and become clear. An expert mechanical engineer described this concept as going “above the clouds;” one moment you were lost in the soup, the next moment you break through the clouds and you can see clearly where you are and where you’re going.

My first revelation was understanding how C code compiled to assembly. Ryan Martell, of Bungie fame, taught me how the machine saw my code, instruction by instruction. All the sudden, many concepts crystalized at once: stack vs. heap, pointers, looping constructs—it all made sense.

Since then, I’ve believed that to understand programming you need to understand what the computer is doing with your programs. That means taking it down to assembly language—the actual instructions running on the CPU. When you think of the computer as a “black box” that just runs code and sometimes produces expected results, sometimes not, your programming will be reflect your hesitance and distrust of the computer. However, when you’ve opened the box and examined the inner workings of the computer running your code, you can program with confidence, because you know exactly what the computer is doing.

This philosophy applies to more than the CPU. You can think of the network the same way; when you request a web page, do you know what bytes are going over the wire? Or consider the disk; when you write a file, do you know exactly what blocks are going where? Or your graphics card; when you draw a 3D object, do you know what gets sent to the graphics processor? I’ll stick to covering the CPU, however, since it’s common to all programming.

Implementation and Abstraction

The first revelation of how a language like C compiles to machine instructions is a revelation of implementation. You understand how the semi-abstract code you’re writing is actually implemented on a real, live computer. We’ll study that.

The next revelation is that implementation down to the very guts of the processor has a balancing force: abstraction. This can likewise be taken to its logical extreme: pure abstraction in which you reason about computing without any actual computer. That may seem bizarre, but we’ll get to that too.

In diving down into implementation and rising up into pure abstraction, the goal is to achieve balance that gives you perspective in your day-to-day programming. I emphatically do not recommend examining the assembly for all of your programming; that’s a waste of time. Neither do I recommend describing your program purely in abstract symbols; you’ve got to write the program at some point. But if you understand both ends—you have that “above the clouds” perspective—then you can program with confidence at any level of abstraction in-between.

(Note: this does not mean your programs will all the sudden become bug free. Shit happens. Sorry.)

Where We’re Going

First, we go down. Down, down, down to i386 assembly. I truly wish I could focus on any assembly language less tortuous than i386, but since that’s what you probably have on your desk, it makes sense to go there. I had the good fortune to learn assembly on Motorola 68K, a processor that made a lot more sense, but as you’ll learn in computing—and life in general—not all change is progress.

Next, we’ll take a step up. Not to pure abstraction, but to considering an abstract machine: the Java Virtual Machine (JVM). For all the Java programmers that think Java is a “get out of C/C++ free” card, sorry, it turns out Java compiles to JVM bytecode in the same way C compiles to machine instructions. The JVM is like a CPU, however it is fundamentally different than any physical CPU I’ve seen.

Finally, we’ll consider “computational thought” without involving a computer at all. This is not an invention of my own, by any means—rather I stand on the shoulders of giants and will refer to some of the foundational texts of our field.