Search This Blog

Sunday, 16 May 2010

Comings and Goings in Programming Languages

Last week I wrote my first GOTO statement in around fifteen years. Strictly speaking it was a JavaScript 'continue' statement, but I specified a label after it to let me jump out of a nested loop, so in my mind it's a GOTO.

At University I was taught that GOTOs and labels were a bad thing because they encouraged spaghetti code. That was ironic, as they also taught me BASIC and Fortran IV, which completely depend on those very same bad things. However, looking at some of the code I used to write back then, I saw their point. Later, when I was writing assembly code for a living, and half your program seemed to be jump statements of one form or another, I really had my nose rubbed in how difficult this style of programming could be.

So for many years now I've tried to steer clear of anything that looked like a GOTO or a label. The nearest I got was in a C program when I mistyped 'default' as 'defualt' and the stupid compiler thought I was creating a label in the middle of a switch statement. (Boy, was that bug hard to spot.)

Going back to my 'continue', I have enough years behind me now to appreciate that jumping out of two loops is no worse than jumping out of one via a 'break', especially as the target label was just a few lines above. But in trying to remember all the arguments against jumps and labels, I suddenly remembered a former colleague saying about a computer language that it was the only one he'd ever met that had the equivalent of a COMEFROM statement.

Sadly, I cannot remember what that language was. A search on the web though found a language that actually does have a COMEFROM statement, namely Intercal. There was also a page explaining how one would work in Fortran. This is all quite amusing, but it's odd how much more difficult the idea of coming from is then going to, even though they're logically equivalent.

For another humorous but fairly unusable computer language, I would recommend Shakespeare, the language that lets your program read like a Tudor play. With true style, that implements a GOTO like this:

Hamlet:
   Let us proceed to scene III.