GOTO considered helpful

How hard is Java?  Hard enough that Stanford CS students start by learning a baby version of it.

How easy is BASIC?  Easy enough that a child could pick up the essentials by looking in a book of BASIC computer games.

David Brin wrote an article a few years ago decrying the demise of BASIC.  What he didn’t say explicitly was that one of the reasons BASIC was so easy was its workhorse of control flow – the GOTO.

The BBC comedy show “Look Around You” opens with someone typing the lines:


20 GOTO 10


and then showing the spooling text.  A joke about computer programming on national TV!  And not one of those XKCD jokes, but one that everyone gets!

GOTO is the most natural statement possible.  A reasonable person might be puzzled by X = X + 1 or even a PRINT statement (do you print the ” as well?  What if you want to print a “?), but how can you misinterpret GOTO 10?  There’s a reason flowcharts and Choose Your Own Adventure books were so popular.

Now, I’m not so crazy as to recommend using BASIC for real programming.  If you’d had to debug a Fortran program with a nine line segment containing five GOTOs, you’d be wary of that too.  But it is a great language for learning programming – even the name and its expansion betrays its orientation towards beginners.

Remember, the most brilliant mathematicians and computer scientists took hundreds of years to come up with functions, objects, and structured programming.  An eleven-year old who’s confused about whether f(x) is a function evaluation or a multiplication has no chance with anything too complicated.  At that stage, just learning how to follow directions is considered a major achievement. Line numbers and GOTOs are perfect for this.

Couldn’t we do all this with a modern language like Python?  It’s a fine language, but, as Lloyd Bentsen might have said “Python, I programmed in BASIC.  I knew BASIC.  BASIC was a friend of mine.  Python, you’re no BASIC.”

Won’t we develop a bunch of programmers with bad habits?  No more so than crawling develops bad habits for running.  And so what if some kids use a few too many global variables.  A few code reviews will whip them into shape, and eventually they’ll put their GOTOs away, or maybe pass them on to some fifth-grader.  But they’ll have had them as training wheels to grow up with.


One Response to “GOTO considered helpful”

  1. Scott Locklin Says:

    I remember when I first learned about recursion in Lisp (and ML). I was all, “dudes; this is GOTO 1” -and, that’s really all it is! Yet, recursion is considered fancy pants, because nerds all wear MC Escher t-shirts. But IRL, it’s GOTO 1. Also, I’m pretty sure every CPU has a GOTO opcode. I guess the idea is GOTO is fine, as long as the compiler does it.

    Most of the Fortran I’ve dealt with lacked GOTO insanity, and was pretty easy to deal with. It’s one of those underrated things. When I was using it, the compilers produced substantially faster code, there were no memory leaks, and no pointer math to screw up. I could never understand why some of the dopes in the physics department wrote their numerics in C just to be “modern.” There’s probably some unstated “Greenspun law” that any sufficiently numeric piece of code is written in Fortran, no matter what language you develop in.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: