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
-
Is anyone else offended by the amount of gotos used in the FS2 code?
-
Originally posted by RandomTiger
Is anyone else offended by the amount of gotos used in the FS2 code?
I doubt it ;)
-
But gotos are horrible and should never be used
-
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
-
Gotos are evil and I've never used them in years of programming in C and C++.
-
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
-
I was brought up to believe they are a sign of bad programming.
-
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 goto init_failed;
just pretend it says throw new InitializationError();
-
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.
-
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.
-
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.
-
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
-
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:
-
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*
-
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.
-
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.
-
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
-
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
-
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...
-
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.
-
dave has a point
-
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.
-
'GOTO' tags are absolutely vital in actionscript (Flash)
i can't think of anything else to substitute it with
-
You bumped a 3 week old thread?
*semi-smack*
-
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?
-
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 :)
-
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...