Quote:
|
But I Sure Know That the Goto Command Can Be Quite Efficient.
|
Forgive me, but you don't know shit about the matter.
A goto is no more efficient that a brace, say, in C/C++. Typically, in a high level language, 'goto' is a statement that causes the path of execution to transfer to a point other than the instruction following in normal sequence. This is a common thing and one of the basic reasons our computers work. The destination of the goto is indicated by a label representing an instruction located somewhere else. The scope or range of this "jump" may be restricted, or it may not be. Because it is a unilateral movement, there's nothing that supports any kind of inference as to whether or not the movement is logical or rational, in terms of program flow.
If you dissect a "while" loop, you get something like this:
TOP:
Evaluate expression.
If expression is false goto END
Do some work here conditioned on the expression being true.
Evaluate some expression, if true goto TOP
Do some more work here
Evaluate some expression, if true goto END
Do some more work here
END
In C, that would look like:
while (expr)
{
Do some work
If some expr2 continue
More work
If some expr3 break
Even more work
}
Note that the 'while' (TOP) is a label who's location is represented by the opening brace.
END is a label representing the, well, end
Continue is a goto to TOP.
Break is a goto to END.
Note that VB would use a WHILE....WEND construct. Languages have various syntactical requirements of their own. PL/Z would use DO....OD.
Note also that the use of euphemistic things like braces, continue, and break, have a salubrious effect. They localize the operation. They are "in view", so to speak. One can see all the possible paths of instruction flow and the logical orderliness thereof. If the goto shoots off thousands of instructions one has no inkling of the rationale behind the construction of the program. Sometimes it goes off, comes back near, shoots off again, ad nauseum. This is referred to as 'spaghetti code.'
One might be tempted (and it might be defensible) to use a goto to exit a deep nest under fatal or near fatal error conditions. It's possible to exit otherwise, but can be a real pain in the rear. Thus the devil tempts us. Linus Torvald and his flunkys overused goto in the kernel. There is some defense, as it is a practical way to deal with exceptional failures,
provided you know what you're doing and what needs to be unwound. The BSD kernel, compared to the Linux kernel, is a fine expression of how to do it better.