Author Topic: Oh my God!.... Its full of gotos!  (Read 5598 times)

0 Members and 1 Guest are viewing this topic.

Offline RandomTiger

  • Senior Member
  • 211
Oh my God!.... Its full of gotos!
Is anyone else offended by the amount of gotos used in the FS2 code?

  

Offline penguin

  • Eudyptes codus
  • 28
  • Still alive.
Re: Oh my God!.... Its full of gotos!
Quote
Originally posted by RandomTiger
Is anyone else offended by the amount of gotos used in the FS2 code?
I doubt it ;)
your source code slave

 

Offline RandomTiger

  • Senior Member
  • 211
Oh my God!.... Its full of gotos!
But gotos are horrible and should never be used

 

Offline Redfang

  • 28
Oh my God!.... Its full of gotos!
Quote
Originally posted by RandomTiger
But gotos are horrible and should never be used

 
I'm not a coder, but I'm still 99,999% sure that they're necessary. :p:D

 

Offline RandomTiger

  • Senior Member
  • 211
Oh my God!.... Its full of gotos!
Gotos are evil and I've never used them in years of programming in C and C++.

 

Offline Redfang

  • 28
Oh my God!.... Its full of gotos!
Quote
Originally posted by RandomTiger
Gotos are evil

 
Have they hit you? Have they killed someone you know? Have they done any damage to anything?
 

 
 
 
:p

 

Offline RandomTiger

  • Senior Member
  • 211
Oh my God!.... Its full of gotos!
I was brought up to believe they are a sign of bad programming.

 

Offline penguin

  • Eudyptes codus
  • 28
  • Still alive.
Oh my God!.... Its full of gotos!
Quote
Originally posted by RandomTiger
Gotos are evil and I've never used them in years of programming in C and C++.
Welcome to the Real World™ ;7

FS2 does not use C++ exceptions, and the gotos in the code (at least the ones I've seen) are used to bail out in case of an error.

Exceptions (C++ and Java) are essentially the same thing as a goto (but they're more palatable to the object-oriented school).  The use of exceptions in C++ generally has a fairly high impact on the size of the generated code, and more importantly, the performance, due to all the frame unwinding.

The FS2 code wasn't designed to be a Grad School project, it was designed to be as fast as possible, while still being fairly maintainable.

So if it makes you feel better, whenever you see
Code: [Select]
goto init_failed; just pretend it says
Code: [Select]
throw new InitializationError();
your source code slave

 
Youre right on the bailout logic,

It's the only legitamite reason to ever use goto's

I used it allot when i wrote components for C (COM).
Makes the code very very readable.
-- The Code Gods --

 

Offline vadar_1

  • Mr. Crispy
  • 29
  • .
    • http://dynamic4.gamespy.com/~freespace/hosted/fullcircle/
Oh my God!.... Its full of gotos!
There are many different ways to bail-out, but the Goto-label system is just bad programming practice. It never has to be used and there is always an alternative.
"Shockingly, checking Draw Lines Between Marked Icons draws lines between the marked icons. " -Volition quality help files

Projects;
The Full Circle Project (site down - server side problem)
Paradox (site down - server side problem)

 
Considering the requirements on speed/performance

What would should they have done in your opinion instead of using 'goto'

Hint: Many of the SDK code samples that microsoft ships with VC6 contain goto's.
-- The Code Gods --

 

Offline IceFire

  • GTVI Section 3
  • 212
    • http://www.3dap.com/hlp/hosted/ce
Oh my God!.... Its full of gotos!
As far as I know, there isn't too much of a reason against goto's.  Its become something of a 'bad form' to highschool teachers abroad (and probably university types too) but frankly...if it means that the game works smoother...I really don't care.  Obviously nobody has for over two years :D
- IceFire
BlackWater Ops, Cold Element
"Burn the land, boil the sea, you can't take the sky from me..."

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Oh my God!.... Its full of gotos!
I think it's mainly the readability factor. Other ways of redirecting  tend to be clearly defined (Think functions...you could use gotos in place of functions, but it would make the code hard to follow).
In general, it's not a good idea to use gotos, but I can think up situations where it would make things easier to follow. :nod:
-C

 

Offline penguin

  • Eudyptes codus
  • 28
  • Still alive.
Oh my God!.... Its full of gotos!
The main arguments against gotos originated in the early days of "structured programming" -- when ALGOL, PL/I, etc, were introduced (and much later, Pascal, Modula, and C).  Before that, there was FORTRAN, COBOL, assembler, etc.  The 'goto' statement coupled with the 'if' statement was about the only flow control statements available.

With the introduction of nested functions (C doesn't support these), local-block scope, and more "structured" flow control statements (while, switch, do, etc.) and early-exit mechanisms (break, continue, return), the goto was much less necessary, and was frequently used by "bad programmers" (ones w/ FORTRAN backgrounds, for example)  when a more appropriate construct could have been used, hence it's bad reputation.

Although the goto statement can almost always be avoided, it can be useful, and can in fact make code more readable and robust (as WMCoolmon pointed out) -- better than 20 nested if (!error) { ... }.

There's a reason why it was left in the C language :)

*steps down from lectern*
your source code slave

 

Offline DTP

  • ImPortant Coder
  • 28
    • http://www.c4-group.dk
Oh my God!.... Its full of gotos!
just a curiosity.

basic :D
------------

10 for t = 0 to 10
20 on t goto 30,31,32,33,34,35,36,37,38,39
30 next
31 goto 30
32 goto 30
33 goto 30
34 goto 30
35 goto 30
36 goto 30
37 goto 30
38 goto 30
39 goto 30

--------
crap, it was sooo easy then, but 65536 lines could get pretty messy.
VBB member; reg aug 1999; total posts 600.
War is a lion, on whos back you fall, never to get up.
Think big. Invade Space.

 

Offline aldo_14

  • Gunnery Control
  • 213
Oh my God!.... Its full of gotos!
Quote
Originally posted by IceFire
As far as I know, there isn't too much of a reason against goto's.  Its become something of a 'bad form' to highschool teachers abroad (and probably university types too) but frankly...if it means that the game works smoother...I really don't care.  Obviously nobody has for over two years :D


it's often a hack... cheap fix.  sometimes you need to, if you're up against deadlines....

the problem is it's a ***** to maintain readability (as has been said)....  you also have to check how variables are being altered when the goto is /is not taken, make sure the right lines of code are being read and suchforth.  It's not great technique, but sometime you have to make sacrifices to get stuff to work on time.

Gotos are pretty redundant with O-O programming, nowadays, I think.

 

Offline Kazan

  • PCS2 Wizard
  • 212
  • Soul lives in the Mountains
    • http://alliance.sourceforge.net
Oh my God!.... Its full of gotos!
ug, i didn't notice, haven't read enough - goto are baaad, you can perform errror handing equally fast wit a different bailout mechanism - just bail out of the function if you have to with a return
« Last Edit: August 06, 2002, 01:54:00 pm by 30 »
PCS2 2.0.3 | POF CS2 wiki page | Important PCS2 Threads | PCS2 Mantis

"The Mountains are calling, and I must go" - John Muir

 

Offline an0n

  • Banned again
  • 211
  • Emo Hunter
    • http://nodewar.penguinbomb.com/forum
Oh my God!.... Its full of gotos!
Quote
Originally posted by DTP
just a curiosity.

basic :D
------------

10 for t = 0 to 10
20 on t goto 30,31,32,33,34,35,36,37,38,39
30 next
31 goto 30
32 goto 30
33 goto 30
34 goto 30
35 goto 30
36 goto 30
37 goto 30
38 goto 30
39 goto 30

--------
crap, it was sooo easy then, but 65536 lines could get pretty messy.


Or a funner variant:

10 print " Mwuahahah"
20 print "whatever"
30 goto 30, 30, 30, 31, 32, 33, 34, 35, 36, 37, 38
31 goto 20
32 goto 20
33 goto 20
34 goto 20
35 goto 20
36 goto 20
37 goto 20
38 goto 20
« Last Edit: August 06, 2002, 02:29:48 pm by 397 »
"I.....don't.....CARE!!!!!" ---- an0n
"an0n's right. He's crazy, an asshole, not to be trusted, rarely to be taken seriously, and never to be allowed near your mother. But, he's got a knack for being right. In the worst possible way he can find." ---- Yuppygoat
~-=~!@!~=-~ : Nodewar.com

 

Offline penguin

  • Eudyptes codus
  • 28
  • Still alive.
Oh my God!.... Its full of gotos!
Hehe, I don't think anyone thinks goto's are a desirable thing in a C program.

But you should be wary of allowing dogma to interfere with your productivity...
your source code slave

 

Offline daveb

  • WHEE!!
  • 25
Oh my God!.... Its full of gotos!
Quote
But you should be wary of allowing dogma to interfere with your productivity...


PREcisely. As a rule of thumb I agree gotos are probably fine to avoid. But the older I get, the more skeptical I am on the knee-jerk reaction "NOOOOOO! GOTOS ARE BAD!" everyone seems to have. Its kind of odd. You always hear that gotos are a hacky way of handling odd conditions. I'd turn the argument around and say that its _far_ smarter to take a readable, simple piece of code and drop a goto in for simplicity's sake than try and re-write/obfuscate/possibly-break it just because you hate gotos. Do _any_ kind of assembly programming (optimization especially) and the concept of a goto becomes very natural. It just blurs the line between an if() and a branch instruction.

I can probably count the # of times I've ever used a goto on one hand and have fingers left over. But when you need one, its really handy.

I also find it odd that you'll find people violently opposing gotos and then blubbering love about namespaces and polymorphism (talk about obfuscation in the majority of cases - oy). gotos are like everything else - they're a tool. Any tool can be abused if you're not careful.