Goto

Everyone in our field knows about Dijkstra’s famous paper Go To Statement Considered Harmful but how many have actually read the paper or know what his arguments were? Mostly we use it as a template to generate memes of the form “\(X\) Considered Harmful.”

Vivek Haldar has a video blog entry in which he reads the paper for us. “Read” means he goes over the paper in detail and talks about the arguments that Dijkstra makes. The paper is short—only one and a half pages—so this isn’t as tedious as it might sound. The video itself is just short of 6 minutes. If you haven’t read the paper, you really should watch the video if only to know what you’re talking about when you invoke Dijkstra’s name.

Dijkstra makes his argument in technical terms. A more succinct and approachable take is presented by Professor David Brailsford in the excellent Computerphile video, GOTO, Goto & Goto. In it, Brailsford says that the point of eliminating gotos is to make our intentions clear. Consider the while loop

while (x > 0)
{    
    do_something_with(x);
    x = x - 1;
}        

and its implementation with gotos

l1: if (x <= 0)
        goto l2;
    do_something_with(x);
    x = x - 1;
    goto l1;
l2:            

No one with more than a week’s experience will have the slightest difficulty understanding the while loop with a single glance but the goto version—especially with a less trivial example—is harder to understand because it’s not immediately clear that we have a loop. What’s the purpose of that first goto, for example? Without reading further down we can’t tell if it’s part of a loop, a simple if statement, or something else.

The Computerphile video, along with some silliness with a Rubik’s cube at the end1, is about five and a half minutes so you can watch both videos in less than a dozen minutes. You should: they’re both worthwhile.

Footnotes:

1

Involving the two Gotos at the end of the video’s title

This entry was posted in Programming and tagged . Bookmark the permalink.