Re: "To goto or not to goto, that, is the question"

new topic     » goto parent     » topic index » view thread      » older message » newer message

Al Getz wrote:

> Hi again Kat,
>
>   The age old argument of the goto or no goto has been around for quite
> a while now.  Arguments started around 1980 or maybe even sooner.  The
> pros and cons seem to boil down to one common factor though, and that's
> whos using the gotos.

Having been around since well before 1980 (and yes, trains had already been
invented, thank you), I can only forward what was then -and is now- a valid
reason for distrusting straight gotos.

>From the very beginning (cf. Ada Augusta, Countess Lovelace) several facts
were clear to every programmer and designer:

a) A program will rarely stay intact forever; sooner or later it will be
added to, modified or in some way changed.
b) This may happen later today, next week, or ten years from now.
c) The changes may be done by the original programmer, but probably not.

All this means that the program not only must work properly. It must also be
readable.

I don't mean nice languages with non-cryptic sentences, nor tons of
documentation, nor fifty-line comments. I mean that when you reach a line
that says "goto sleep," you must be able to find a label called "sleep." An
also that when you reach the "sleep" label, you should be able to tell why
it's there, i.e. from which place or places in the program there's a jump
there.

I've never found a compiler or interpreter that will tell you that, unless
it can also print out an xref map, which can run to many pages, is normally
quite unreadable itself, and most people tend to ignore.

In fact, most compilers will let you insert labels wherever you like,
whether they are valid destinations or not. And several compilers I've
worked with would let you put a goto without the corresponding destination
label, and wouldn't holler until the procedure was actually ran, for they
treated it as a runtime error and not as a compile error (at most, they'd
insert a warning).

There's nothing wrong with gotos. In fact, most programs are chock full of
gotos, even if you don't see them. And I'm not partial to languages that
forbid them, as in the times of structured programming. But a programmer who
uses gotos had better never lose control of them. The only practical way
I've found to do this is to comment my every jump, even if it's just a memo
to myself tomorrow morning. Too many times I've had a program turn up
unexpectedly where it shouldn't have, and spend hours and days (literally;
try cobol-74 someday) drawing a map of the program just to detect where it
might have gone.

One final piece of boring experience: if your gotos gang up on you, try to
straighten them out only so far. Ask for help. After a few hours all your
wires are crossed, and you wouldn't see the connection if it bit you. Print
your source, don't read it onscreen. Read it aloud. Pay the price. Sigh...

Gerardo E. Brandariz



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu