IT PAPER DEEP-READ · PAPER 37

Go To Statement Considered Harmful

Edsger W. Dijkstra · Communications of the ACM · 1968

中文 →

What did this paper do?

In 1968, the Dutch computer scientist Edsger Dijkstra wrote a two-page letter to an academic journal, titled Go To Statement Considered Harmful. It contained no algorithm and no formula, yet it became one of the most famous pieces of writing in software history and rewrote how we think about "how code should be written." The if / while / for you write today — and the goto that nearly every language now urges you to avoid or has removed entirely — trace back to this letter.

First, what is goto?

Early programs looked like a list of numbered lines, and goto was a command: "stop reading down the page — jump straight to line 87 and continue there." It could jump forward, jump back, jump into or out of anything. Convenient, genuinely. But stuff a sizeable program full of these jumps and reading it feels like untangling a knotted pair of earbuds — the trade name is "spaghetti code."

The subtle thing Dijkstra saw

He pointed out something delicate: we read code top to bottom, line by line (static text), but a program actually runs step by step through time (a dynamic process). Whoever writes the program must constantly line up those two things — "this line I'm reading corresponds to this step of the run." And he had an observation about people: humans are naturally good at grasping static arrangements, but rather poor at picturing a process that unfolds over time. So the key to good code is to make the static text as much like a map of the dynamic execution as possible.

The idea

goto is exactly what rips that map apart. Here's an analogy: reading an ordinary book, a single bookmark tells you where you are. But if every page said "now jump to page such-and-such," bouncing around, the bookmark loses its meaning — from the bookmark alone you couldn't say how far the story has gotten or what happened before.

Dijkstra's claim: using only three "non-jumping" building blocks — go straight down (sequence), pick one of two (an if branch), and repeat (a loop) — is enough to write any program; and code written that way always admits a crisp bookmark of the form "which line I've reached + (if inside a loop) how many times around." The text becomes a reliable map again.

What it led to

The letter ignited the "structured programming" movement. New languages made if/while/for first-class citizens and pushed goto to the margins; "code should be readable by a human" was, for the first time, placed on equal footing with "it runs." You almost never see goto in serious code today, largely thanks to this letter. One honest caveat: Knuth and others later noted that in a few cases (say, bailing out of several nested loops at once on an error) a single jump reads more clearly — so the mainstream stance is "use it very sparingly," not "ban it outright."

Remember this

Code is static text; execution is a dynamic process; the human mind is good at the former and poor at the latter. goto can jump anywhere, so "where you're reading" no longer matches "where the run is" — the text stops being a map. Switch to sequence / branch / loop and you can always pin the program's current position with a clear bookmark — so the code becomes readable, checkable, trustworthy.

Want the precise "progress-coordinate" argument, a control-flow comparison diagram, and the later debate? → switch to the Deep version