Thomas Stegen said:
That the argument "This code is bad because it uses goto" is
bogus.
And that's where I (partially). disagree Code containing goto's
without a very good reason, is bad. The same goes for 'break'
(in loops, not switches) and 'continue'.
Which is what the statement "Never use goto" basically
boils down to.
For rookies, it's my usual advice. Experts (generaly) know good reasons to
employ goto and do not use it without.
Most people who argue against goto and invoke
Dijkstra just spout Dogma and usually haven't even read Go to
Statement Considered Harmful.
That's their miss.
Which is a paraphrase of what I said originally.
I think it's the other way around.
Besides
<quote Go to Statement Considered Harmful, E.W. Dijsktra.>
More recently I discovered why the use of the go to statement has such
disastrous effects, and I became convinced that the go to statement should
be abolished from all "higher level" programming languages (i.e. everything
except, perhaps, plain machine code).
</quote>
Dijkstra argues in favor of abolishing goto alltogether in higher level
languages. And
<quote>
The unbridled use of the go to statement has an immediate consequence that
it becomes terribly hard to find a meaningful set of coordinates in which to
describe the process progress.
[...]
The difficulty is that such a coordinate, although unique, is utterly
unhelpful. In such a coordinate system it becomes an extremely complicated
affair to define all those points of progress where, say, n equals the
number of persons in the room minus one!
</quote>
He cites (allbeit paraprased) breaking invariants as one (if not, the main)
reason.
So when you start arguing why goto is bad you are entering a
completely different debate.
I think not. In fact, you make it clear that I understood correctly the
first time round.
I am saying that most people who
are vehemently against goto are just regurgitating what someone
else has already regurgitated.
In the abstract I dare put forth the following as truth:
If a piece of code can be best improved by using goto then goto
should be used.
Ok. I'll follow.
* This is a very rare occasion.
* If that piece of code becomes harder to maintain/understand, i'll throw
your "truth" (and the goto with it) out of the window.
Admittedly the second does depend on what you call "improved".
But that is self evident. I have never used goto myself, but if
I find myself in the right situation, I will. So there you have my
view on using goto. (These last three lines, the previous lines
are my view on brainless dogma).
You, perhaps, discount other views as "brainless dogma" too soon.
And as a small disclaimer, I am not pointing the finger at anyone
in particular as I am not a mind reader. You will know yourself
whether this applies to you or not.
It is hard to write, because it is hard to read. Hence the previous two
paragraphs.
I'll quote Dijkstra again.
"The go to statement as it stands is just too primitive; it is too much an
invitation to make a mess of one's program. "
And
"The remark about the undesirability of the go to statement is far from new.
I remember having read the explicit recommendation to restrict the use of
the go to statement to alarm exits, but I have not been able to trace it;
presumably, it has been made by C. A. R. Hoare. In [1, Sec. 3.2.1.] Wirth
and Hoare together make a remark in the same direction in motivating the
case construction: "Like the conditional, it mirrors the dynamic structure
of a program more clearly than go to statements and switches, and it
eliminates the need for introducing a large number of labels in the
program."
And leave you with these remarks for consideration.