GOTO - A Virtual Lifesaver
Norman L. DeForest
A few years ago I read about how a FORTRAN programmer used lots of
GOTOs to solve a problem he had.
Background
- The version of FORTRAN he was using allowed multiple statements on a
line using '$' as a statement separator.
- Many of his programs had tens of thousands of statements.
- The system used punch cards.
- He couldn't take the cards to the machine himself. The protocol at
his place of work required that all jobs had to be submitted to a
central office and, from there, the card decks would be taken by
secretary to the computer and loaded by them.
- The secretaries had a bad habit of dropping card decks and getting
them mixed up.
- Punching sequence numbers on the cards allowed them to be resorted but
that had to be submitted as a new job -- with no guarantee that the
cards wouldn't be dropped again after sorting and before being
re-submitted for compiling.
His Solution
- He numbered every statement.
- Each card that had a GOTO was left alone since it jumped to another
statement. (For conditional branches, that version of FORTRAN used
arithmetic GOTOs where IF branched to one of three specified
statements depending on whether the expression in the IF was negative,
ro, or positive.)
- Each card that didn't have a GOTO had one added, going to the next card:
...
...
12347 ...
12348 SALARY = RATE * HOURS $ GOTO 12349
12349 OVERTIME = RATE * 1.5 * OVRHOURS $ GOTO 12350
12350 ...
...
...
- He used colour-coded cards for the JCL[1], the first statement in the
program, and the last statement in the program.
If the card deck was dropped and mixed up, he only had to find the
colour-coded cards and put them in the right place. Regardless of the
spaghetti-code nature of the rest of his program, it would compile and run
correctly no matter what order the rest of the cards were in.
No amount of "structured programming" could have solved that problem. :)
[1] JCL: Job Control Language.
Original posted to alt.www.webmaster; Message-ID
<Pine.GSO.3.95.iB1.0.1050905063156.22981A-100000@halifax.chebucto.ns.ca>
Back to Computing/Other