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 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.
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderANd now, for something completely different... I am currently contemplating sticking a *bunch* of gotos in my next component. It's C, it's an authentication component, and therefore its logic is something like: IF (bad user id) { error=BAD_ID; skip the rest except the last piece; } IF (bad PSW) { error=BAD_PSW; skip the rest except the last piece; } ... last piece: record to log file/DB what happened; return Success/Failure So.. a *big bunch* of nested if's, or a *big bunch* of if-else's, or a *big bunch* of gotos Aside, if no-one notices, I'm sure tempteds to use the gotos just 'cause ! I'd stop only if it would lead to the problems I hit in Assembly, when the label is too far, but I have never seen that problem in C/C++. Geee... they gave use a goto statement... let's use when appropriate ! F.O.R.
-
wasnt 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 MaunderEvery instance of
goto
is a mistage! Exception: in asm you have to move from one place to other but there the instruction is called code>jmp, to distinguise it fromgoto
found at hi-level languages! (conclusion: goto is an instruction which you can avoid under every circumstanced) - - - - - - - - - - - - - - - - - - Memory leaks is the price we pay \0 01234567890123456789012345678901234 -
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderI think that ""goto considered harmful" considered harmful" is the correct approach here. Like all programming constructs, there is an appropriate time and place for it (and that's college). Goto is unfortunate in the respect that it's easier to abuse than most, and has significantly fewer (NOT 0!) sane uses. Two notable uses I can think of are
on error goto
in pre .NET VB, and in some BASIC variants you could dogoto i * 1000
(which was sometimes useful for menus and stuff) but I'm sure everyone will just toast me for reminding them ;p ) After all,goto
is just a more general version ofgosub
, which required more care:80 let ret=100 90 goto 1000 100 rem Next bit 1000 rem Do something 1010 goto ret
:laugh::laugh::laugh: -- Ian Darling If I was any more loopy, I'd be infinite. -
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 like break and continue... :) Please, can someone explain what's so bad about them? Can you really wtite :readable: code without continue and break? - - - - - - - - - - - - - - - - - - Memory leaks is the price we pay \0 01234567890123456789012345678901234
-
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.