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 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. -
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
theres nothing wrong with using break, continue OR goto cheers Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris Maunder10 ?"Hello world"
20 goto 10Regards Thomas
Disclaimer:
Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you. -
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderWe had a function that contained this:
void MyFunction()
{
start:
goto end;//
// LOTS of code
//end:
goto start:
}The programmer in question was "experimenting" with different ways to lock up a program. Unfortunately, his short-term memory wasn't the best in the world, and he forgot he had put this into our production code along with this gem:
for ( ; ; ) ;
and this:
bool x = true;
do {} while (x==true || x==false);By the way chris, there's a bug in the pre parsing (probably in IE, but I thought you should know). In the for() loop above, I got the winking smiley if i didn't put a space between the characters. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 "You won't like me when I'm angry..." - Dr. Bruce Banner Please review the Legal Disclaimer in my bio. ------- signature ends
-
What's the most gratuitous, inane, innappropriate or just plain wrong use of the
goto
keyword you've seen? cheers, Chris MaunderI had a boss once that maintained most of the code of a major application. I ended up with that code 2 years later. He had a single 2000 line function (he was an old Assembly programmer. Also wrote Cobol Compilers) that did most of the work. He had many gotos in this function. My favorites were the 2 that worked together. One Goto broke out of a 2 deep nested while loop. It went to a 5 line block of code inside a for loop 300 lines down. On completion of that 5 lines of code (keep in mind, it never initialized the for loop), it might return through its companion goto back to where it was called from. (goback to original goto and continue processing). If the condition failed, (which it never did, to my knowledge) it would continue processing inside that uninitialized for loop. We ran this function through some complexity mapping software. It generated a text map of each function with a number 1-10 for complexity. (1 being a linear function, and 10 being a complex == bad function). It also returned a graphic map of each line of code (vectors through each statement, conditions, loops, etc). This function returned a complexity of over 2000! The graphic map generated looked like a street map of south FLORIDA!! (To the dirt road level). "It takes a minimum of redesign to turn a crucifix into a pogo stick"
-
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.Fascist. ;P
Who is 'General Failure'? And why is he reading my harddisk?!?