PDA

View Full Version : Someone used a goto...



adrianxw
01-29-2003, 12:03 PM
Hey guys, quietly so we don't frighten anyone, but someone here is using a goto , it's true, look...

http://cboard.cprogramming.com/showthread.php?s=&threadid=33368

Govtcheez
01-29-2003, 12:06 PM
I thought that was a myth!

biosninja
01-29-2003, 12:09 PM
*cough*aaaaarrrgggghhhh!!!!*cough*
:p

Shiro
01-29-2003, 01:04 PM
Hmmm. I hope the poster of that thread was not taught to do so... :(

biosninja
01-29-2003, 01:07 PM
Yeah...he should goto....*ahem*
enough said

Travis Dane
01-29-2003, 01:07 PM
I wonder why C++ was equiped with a goto statement anyway,
I mean it's totally wothless, it's bad code.

biosninja
01-29-2003, 01:09 PM
Propably for people who want's a (bad) easy way out

ober
01-29-2003, 01:23 PM
Ya know... I never thought I'd need a goto statement either, but I actually used one the other day. It's not in a loop or anything... I just jump past some code with it. I didn't feel like using a giant if statement.

Cela
01-29-2003, 01:35 PM
>>I wonder why C++ was equiped with a goto statement anyway, I mean it's totally wothless, it's bad code.
Why is it bad code? I mean if you think about it, the most contrived language out there, Ada, has goto. If it were really that bad then why do all these languages have it? If goto is the most natural solution then that's what you should use, I don't see what all the fuss is about. :-)

adrianxw
01-29-2003, 01:39 PM
C++ retains the goto for backward compatibility. I don't know what ADA's excuse is. ADA is a mess isn't it.

Cela
01-29-2003, 01:49 PM
>>ADA is a mess isn't it.
You can say that again :-)

Eibro
01-29-2003, 01:56 PM
What a rare sight indeed! I've only ever seen them in captivity... these wild ones look quite a bit more fierce.



Hmm...
Has anyone ever seen the commercial with the miniture house hippos in it? If only one were made about goto...

PJYelton
01-29-2003, 02:11 PM
[Crocodile Hunter voice]

Crikey, she's beauuuuutiful!

Travis Dane
01-29-2003, 02:20 PM
Originally posted by adrianxw
C++ retains the goto for backward compatibility.

With BASIC? euhm...no

adrianxw
01-29-2003, 02:28 PM
>>> With BASIC? euhm...no

With C :rolleyes:

Travis Dane
01-29-2003, 02:32 PM
Originally posted by adrianxw
With C :rolleyes:

Then why the hell was goto included with C???

adrianxw
01-29-2003, 03:07 PM
Presumably because the original authors of C were providing the same kind of functionality that was available in other programming languages of their era - it was a hell of a long time ago. Not all languages had structured if statements, for example. In Fortran-66 for example, an if is...

IF(X.EQ.Y)statement

...where statement is a single statement, no compound statements allowed. As a result you often got blocks of code like...


IF(X.GT.1)GOTO 10
Y=1
10 IF[X.GT.2)GOTO 20
Y=2
20 IF(X.GE.3)GOTO 30
Y=3
30 CONTINUE


... if you are trying to encourage people to drop their language and use yours, you make it easy. When I coded in Fortran-66 I used GOTO, it was the only way to do certain things. I have not used a goto after the introduction of Fortran-77.

*ClownPimp*
01-29-2003, 03:34 PM
Have you guys heard of yEnc, the new encoding method for binary attachments in Usenet? Well, I wrote some code that used that scheme and you'll never guess what I saw in the C implementation that i downloaded... it was nothing but goto's!! I mean, not a single for or while loop, all goto's! Needless to say, I quickly abandoned that implementation for a different one :p


On another note, why has goto's become so evil in the eyes of so many? There are legitimate uses for them (IMHO), like jumping to code on an error, breaking from nested loops..., where the non-goto alternative would be less efficient and less readable.
As long as its used very sparingly I dont see any downside to using it

*puts on fire-retarding suit in preparation for the inevitableflames*

for some reason I can't seem to spell today

-=SoKrA=-
01-29-2003, 04:22 PM
Originally posted by *ClownPimp*
As long as its used vary sparingly I dont see any downside to using it
That's the way I see goto's. Personaly I've never used one but imagine you're in the middle of a loop that's nested 5 or 6 times and you want to go to a place at the other side of the file. What do you do? Either use goto or a piece of code that only 4 people are able to understand 2 days after you wrote it. :p
>>*puts on fire-retarding suit in preparation for the inevidable flames*
Got a spare one?

Unregd
01-29-2003, 05:55 PM
This goto looks like subtratum from someone's previous programming experience in a programming language that shall remain nameless (cough, Q, cough, Basic, cough). For what my opinion's worth, if goto is necessary for the code as is, there is probably a more elegant solution without it. Someone be sure to remind that poor kid to write a program that displays, "I will not use goto in my C/C++ code," a hundred times.

BMJ
01-29-2003, 06:22 PM
I was browsing the Half-Life Dedicated Server source code today and found this line...
fflush(stdin);:D

Silvercord
01-29-2003, 07:58 PM
I don't see what's so bad with it. I mean you are after all using a language where false is synonomous with excitement (!).

Jane: Oh Robert! Oh Robert!
Robert: What? My sex is evaluating to false? I'm a bad lover! :(

dirkduck
01-29-2003, 10:22 PM
Oh come on now, its not that bad. I mean if its not overused, it can be handy get get out of/into a loop or whatnot without a load of if's.

adrianxw
01-30-2003, 02:43 AM
>>> it can be handy get get out of/into a loop or whatnot

That is the usual justification. I would say that it is not valid, you can always get out of nested structures, and I would also say that if your program has very deeply nested structures, there was probably a better way of doing it anyway.