Most gratuitous use of 'goto'
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderHere's what I could come up with in these early morning hours :-
void GetBiggest(int x, int y, int z, int& big)
{
for(big = x; big < y; )
goto check1;
for(; big < z; )
goto preexit;
goto exit;
check1:
for(big = y; big < z; )
goto preexit;
goto exit;
preexit:
big=z;
exit:
;
}I hope, it's okay for your purpose Chris. :rolleyes: Nish
Extending MFC Applications with the .NET Framework [NW] (coming soon...) Summer Love and Some more Cricket [NW] (My first novel) Shog's review of SLASMC [NW] Come with me if you want to live
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderI once (many years ago) used
goto
to swap two lines in my basic code (something like this):goto a1
a2:
' something in basic
goto a3
a1:
' something in basic
goto a2
a3:because on my laptop* didn't work
Cut
andPaste
and this lines were to long :-D. Am I winner :) ?
*) My laptop: 5MHz (10 with turbo) CPU; 1MB RAM; No harddisk; 640x200 display with two colors (yellow and blue):rolleyes: i'm only pointer to myself
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris Maunderwasnt this a non-coding forum!? :cool: Don't try it, just do it! ;-)
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderI ran across some code where 'goto' was used to go to the end of a 'for' loop and do the next case. I think it's beause somebody didn't know about the continue statement. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
-
wasnt this a non-coding forum!? :cool: Don't try it, just do it! ;-)
I said "goto" not "coding". There's a difference :P cheers, Chris Maunder
-
I ran across some code where 'goto' was used to go to the end of a 'for' loop and do the next case. I think it's beause somebody didn't know about the continue statement. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
I have come across quite a few programmers that don't know about continue.
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderWell, when i was very young, i wanted to stay up and watch TV all night, but my mom said "
goto
bed." I certainly felt that was inane, as well as just plain wrong. ;PShog9
I returned and saw under the sun, that the race is not to the swift, nor the battle to the strong...
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderAnyone on my team who dare's using
goto
is fired on the spot :mad: -
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderWhen my ex-wife said "goto he..!!!". Marc Latest AAL Article My blog Join my forum!
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderA number of years ago Microsoft published the DefWndProc source code, which is what you call from your WndProc after you have processed a windows message. I believe the function was over 3000 lines of code, although I have seen such long switches in Excel functions, too, but maybe not that long. There was a label called "ICantBelieveIUsedGoto" in the function, that went from one location of the function to another location. What I don't understand is why each case could have been broken out into a separate function, thus making it easier to maintain. Oh, yes, I remember, because this was windows 3.1. Thanks, Wes
-
Anyone on my team who dare's using
goto
is fired on the spot :mad:are they allowed to use "continue" and "break" ? bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor
-
are they allowed to use "continue" and "break" ? bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor
I have been programming for 20+ years and never ever found any use for
continue
orbreak
(except off coursebreak
in aswitch
statement), so to answer your question, no, they cannot. The same goes for thereturn
statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements likegoto
,continue
,break
andreturn
(the latter used in the wrong place) leads too often to "spaghetti code" IMHO. -
I have been programming for 20+ years and never ever found any use for
continue
orbreak
(except off coursebreak
in aswitch
statement), so to answer your question, no, they cannot. The same goes for thereturn
statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements likegoto
,continue
,break
andreturn
(the latter used in the wrong place) leads too often to "spaghetti code" IMHO.as long as you're consistant :) i've heard people moan about the use of "goto" but they'll happily use break and continue... bit oxymoronic if you ask me :) Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor
-
I have been programming for 20+ years and never ever found any use for
continue
orbreak
(except off coursebreak
in aswitch
statement), so to answer your question, no, they cannot. The same goes for thereturn
statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements likegoto
,continue
,break
andreturn
(the latter used in the wrong place) leads too often to "spaghetti code" IMHO.I do use continue and break probably 1 time in every 10K lines of code I write. The multiple returns probably 1 in every 2K lines. I have not used a goto in several years so the ratio will probably be like 1 in every 250K lines I write... John
-
I have been programming for 20+ years and never ever found any use for
continue
orbreak
(except off coursebreak
in aswitch
statement), so to answer your question, no, they cannot. The same goes for thereturn
statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements likegoto
,continue
,break
andreturn
(the latter used in the wrong place) leads too often to "spaghetti code" IMHO.There are definitely times when using continue, break, and return is actually better than not doing so. But when you find yourself needing to do it, it's important to ask yourself if there is a better way - breaking the function up into multiple functions, etc. If you say absolutely no gotos/continues/etc, occasionally you'll run into a place where in order to go by your rules you'll have to produce code that's more like 'spaghetti code' than if you allowed its use. * Believe me - I've seen this before (not very often, though). *Most of the cases were in complex string parsing functions.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
There are definitely times when using continue, break, and return is actually better than not doing so. But when you find yourself needing to do it, it's important to ask yourself if there is a better way - breaking the function up into multiple functions, etc. If you say absolutely no gotos/continues/etc, occasionally you'll run into a place where in order to go by your rules you'll have to produce code that's more like 'spaghetti code' than if you allowed its use. * Believe me - I've seen this before (not very often, though). *Most of the cases were in complex string parsing functions.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhijdunlap wrote: If you say absolutely no gotos/continues/etc, occasionally you'll run into a place where in order to go by your rules you'll have to produce code that's more like 'spaghetti code' than if you allowed its use. * Believe me - I've seen this before (not very often, though). These are the cases that I would use it. John
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderI for one actually don't know how to use 'goto' Nor do I understand why it is used. Regardz Colin J Davies
*** WARNING *
This could be addictive
**The minion's version of "Catch :bob: "It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox
-
I have been programming for 20+ years and never ever found any use for
continue
orbreak
(except off coursebreak
in aswitch
statement), so to answer your question, no, they cannot. The same goes for thereturn
statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements likegoto
,continue
,break
andreturn
(the latter used in the wrong place) leads too often to "spaghetti code" IMHO.AgedToPerfection wrote: (except off course break in a switch statement), I won't allow anyone to use sloppy switch statements in my projects. So I can't see the point of having a break at all. Regardz Colin J Davies
*** WARNING *
This could be addictive
**The minion's version of "Catch :bob: "It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris Maunderhere: TRACE(_T("I love Code Project and me! hehe haha\n")); goto here;
I think the only time I've ever used goto was for "cleanup" purposes within a function. I do remember coming across a Microsoft VC++ sample that used goto - if I'm not mistaken it was one of the multimedia samples.My 20 favorite films:
http://www.ymdb.com/user_top20_view.asp?usersid=8912 -
I have come across quite a few programmers that don't know about continue.
Tim Ranker wrote: I have come across quite a few programmers that don't know about continue. ..ehr... I continue to run into gotos... ...(double)ehr... F.O.R.