Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: RandomTiger on August 01, 2002, 01:23:55 pm

Title: Oh my God!.... Its full of gotos!
Post by: RandomTiger on August 01, 2002, 01:23:55 pm
Is anyone else offended by the amount of gotos used in the FS2 code?
Title: Re: Oh my God!.... Its full of gotos!
Post by: penguin on August 01, 2002, 02:26:59 pm
Quote
Originally posted by RandomTiger
Is anyone else offended by the amount of gotos used in the FS2 code?
I doubt it ;)
Title: Oh my God!.... Its full of gotos!
Post by: RandomTiger on August 01, 2002, 02:28:26 pm
But gotos are horrible and should never be used
Title: Oh my God!.... Its full of gotos!
Post by: Redfang on August 01, 2002, 02:36:32 pm
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
Title: Oh my God!.... Its full of gotos!
Post by: RandomTiger on August 01, 2002, 02:42:50 pm
Gotos are evil and I've never used them in years of programming in C and C++.
Title: Oh my God!.... Its full of gotos!
Post by: Redfang on August 01, 2002, 02:47:57 pm
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
Title: Oh my God!.... Its full of gotos!
Post by: RandomTiger on August 01, 2002, 02:52:36 pm
I was brought up to believe they are a sign of bad programming.
Title: Oh my God!.... Its full of gotos!
Post by: penguin on August 01, 2002, 03:29:25 pm
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();
Title: goto's only for bailoot
Post by: Jacob Bogers on August 01, 2002, 07:14:11 pm
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.
Title: Oh my God!.... Its full of gotos!
Post by: vadar_1 on August 01, 2002, 07:26:59 pm
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.
Title: Arguments
Post by: Jacob Bogers on August 01, 2002, 07:39:34 pm
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.
Title: Oh my God!.... Its full of gotos!
Post by: IceFire on August 01, 2002, 08:19:49 pm
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
Title: Oh my God!.... Its full of gotos!
Post by: WMCoolmon on August 01, 2002, 09:34:09 pm
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:
Title: Oh my God!.... Its full of gotos!
Post by: penguin on August 02, 2002, 11:49:33 am
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*
Title: Oh my God!.... Its full of gotos!
Post by: DTP on August 02, 2002, 09:33:18 pm
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.
Title: Oh my God!.... Its full of gotos!
Post by: aldo_14 on August 03, 2002, 10:13:02 am
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.
Title: Oh my God!.... Its full of gotos!
Post by: Kazan on August 06, 2002, 01:49:59 pm
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
Title: Oh my God!.... Its full of gotos!
Post by: an0n on August 06, 2002, 02:27:04 pm
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
Title: Oh my God!.... Its full of gotos!
Post by: penguin on August 06, 2002, 04:26:54 pm
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...
Title: Oh my God!.... Its full of gotos!
Post by: daveb on August 06, 2002, 08:07:22 pm
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.
Title: Oh my God!.... Its full of gotos!
Post by: Kazan on August 07, 2002, 08:53:33 am
dave has a point
Title: Oh my God!.... Its full of gotos!
Post by: aldo_14 on August 07, 2002, 04:28:37 pm
It's easy to #### stuff with gotos when you're learning.... so (in my experience) use of them is discouraged - so you tend to regard them with a sort of deep distrust.  I've not really had any deep experience with C or C++ - only Java (although i might do some more interesting stuff for me group project next year ;7 ), but I think that gotos tend to become far less necessarry the higher up the language becomes.
Title: Oh my God!.... Its full of gotos!
Post by: Stealth on August 29, 2002, 03:08:58 pm
'GOTO' tags are absolutely vital in actionscript (Flash)

i can't think of anything else to substitute it with
Title: Oh my God!.... Its full of gotos!
Post by: an0n on August 29, 2002, 03:23:23 pm
You bumped a 3 week old thread?

*semi-smack*
Title: Oh my God!.... Its full of gotos!
Post by: vyper on August 29, 2002, 03:27:28 pm
Quote
Originally posted by aldo_14
It's easy to #### stuff with gotos when you're learning.... so (in my experience) use of them is discouraged - so you tend to regard them with a sort of deep distrust.  I've not really had any deep experience with C or C++ - only Java (although i might do some more interesting stuff for me group project next year ;7 ), but I think that gotos tend to become far less necessarry the higher up the language becomes.


Group project? U ain't doing Computing BSc at uni are you?
Title: Oh my God!.... Its full of gotos!
Post by: Stealth on August 29, 2002, 10:17:28 pm
Quote
Originally posted by an0n
You bumped a 3 week old thread?

*semi-smack*


damn i'm sorry :(  i didn't look at the dates


only reason i replied in it, was because i was looking at the "whos online" and some 'guest' was looking at it

lol, i like the semi-smack though :)
Title: Oh my God!.... Its full of gotos!
Post by: Zarax on August 30, 2002, 12:49:46 am
As a former COBOL :shaking: programmer, (i'm on Java and VB now) i can say that GOTOs aren't so bad...
Many programs (not games) are often just updated from older languages (like COBOL and so on) and GOTO's in the right places are an useful tool, that saves time and code lines...