"Herbert Rosenau" <os****@pc-rosenau.dewrites:
On Wed, 20 Aug 2008 21:00:55 UTC, ri*****@cogsci.ed.ac.uk (Richard
Tobin) wrote:
>In article <wm***************************@JUPITER.PC-ROSENAU.DE>,
Herbert Rosenau <os****@pc-rosenau.dewrote:
>No, got breaks the flow. It requires a label somewhere.
So it breaks the flow. So what? Are you suggesting that correctly
written programs have unbroken flow?
>The existence
of a label is a sign to seharch for multiple gotos somewhere else. and
breaks the flow only because it exists.
Most functions I've written that use goto have only one label.
wheras a label has always an unknown number of source. So goto makes a
program unmaintable always!
It doesn't matter if a function has currently ony one ore one million
gotos. Having a lable makes the whole program unmaintable because at
the point the label exist there is absolutely nothing that says that
this label is reached fom only one point and where that point is and
what state the flow has. There is in no way a need for goto. There is
noways a need to set a lablel as destination of a goto. When you means
you needs a goto then your design is highly buggy and needs to be
replaced by another one.
[...]
As many people have said, "All generalizations are false, including
this one".
I don't remember the last time I used a goto (other than in some
scripting "language" that really didn't have anything better); I'm not
sure that I've *ever* written a goto in C.
Having said that, a goto statement and its target label are always
within the same function. If that function is short enough, a moment
of reading is enough to ensure that there's only one goto statement
and only one label.
For example:
int foo(blah)
{
for (blah; blah; blah) {
for (blah; blah; blah) {
if (need_to_bail_out_now) {
goto ERROR;
}
}
}
return OK;
ERROR:
return ERROR_FLAG;
}
Given sufficiently clear identifiers, the control flow is fairly
obvious and maintenance shouldn't be too much of a problem. Here the
goto statement substitutes for C's lack of a multi-level break.
Now a lot of programmers would restructure this code to avoid the
goto. I would very likely do so myself. But that's largely a matter
of taste. The (pseudo-)code as written, even with a goto statement,
isn't "highly buggy".
Yes, every program that uses gotos can be rewritten to avoid them;
that's a theorem that's been known for decades. That *doesn't* imply
that the gotoless version is unambiguously better.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"