Joe Woodbury wrote:
I've found that once you tolerate any use of goto, some developers will abuse it severely. Not only does it create difficult to understand code, it causes scope problems and, worse of all, results in poor algorithms. I have learned this by experience. I have maintained a lot of code chock full of gotos, but I have chosen to use one precisely once in nineteen years of C/C++ programming.[...]
We have different experiences. I've seen very few goto's as a professional programmer ... wait, except for those FORTRAN days. Actually, that's going to tie into the point I'm about to make. Different languages have different program control mechanisms. I used to program in a language called Clarion. One of the constructs I likes in that language was the ability to write loop 1 times
. No index variable. I would wrap it around a series of if/then/else if and break
to exit early. In C/C++, I accomplish the same with this
while (true) // loop 1 time, exit at bottom
{
if (set (ifrFragment))
{
result = true;
ifrTerm = ifrFragment;
break;
}
if (errorCode)
break;
if (keyword (TokenSubtype::Not) && term (ifrFragment))
{
result = true;
ifrTerm = TokenSubtype::Not.asString() + " " + ifrFragment;
break;
}
if (errorCode)
break;
// more lines snipped
break;
}
Robert Surtees writes We used to do it to piss off the "never use goto" zealots years ago when forbidden to use 'goto xit' for handling error conditions. And he's right. I could have done the same like this, with one few level of indentation:
if (set (ifrFragment))
{
result = true;
ifrTerm = ifrFragment;
goto exit\_;
}
if (errorCode)
goto exit\_;
if (keyword (TokenSubtype::Not) && term (ifrFragment))
{
result = true;
ifrTerm = TokenSubtype::Not.asString() + " " + ifrFragment;
goto exit\_;
}
if (errorCode)
goto exit\_;
// more lines snipped
exit_:
So in the first example, I'm doing goto's -- without using them explicitly. Anyway, to get to my point: since different language have different control