Mail Archives: djgpp/2000/08/03/19:00:15
Newsgroup: comp.os.msdos.djgpp
From: manni DOT heumann AT gmx DOT de (Manni Heumann)
On Thu, 03 Aug 2000 20:36:39 GMT
>djgpp AT delorie DOT com wrote:
>>>Try 'goto'. You'll love it. They never taught you about it in
>>>school.
>>
>>EEK! There are reasons for this! GoTo is "forbidden"! Nicer is to put this
>>into a function
>>that returns TRUE/FALSE. So, as soon as a collition is detected, you jump
>>out of the
>>function with false. This will break the loops. Might be considered cheating
>>but it
>>helps for making the code more usable so there is a good fix to this
>>problem.
>>
>
>Name just one of those reasons agains goto, other then "it looks like
>BASIC and real hardcore C coders don't use that kiddy stuff."!
If you give in to the temptation of using goto, you might consider
using it more often. Too many goto's will make your code completely
unreadable (yup, I started in BASIC too).
>I didn't yet see one solution in this thread, that was as easy to read
>as a simple little goto.
Not exactly true, IMO.
> Checking a flag for every for,
Granted.
>building the whole nest in a function and return?
No, this is the way to do it. I always split my code in small
functions that perform logical tasks, collision detection would be one
of these.
>Picture yourself reading that code!
Doing it all the time. Actually, I find something like
if (sprites_collide(sprite1, sprite2))
do_mega_big_explosion();
very readable.
>Goto will also give you the benefit of feeling superior to the
>moron who still uses goto after all this years:-)
Sorry, you've lost me.
>Back to the beginning: Name one reason against using goto. At least
>name the law the forbids using goto.
Using goto often will result in code that is harder to read. Cases
where goto is needed can usually be worked around using functions (as
in this example).
>Come on, convince me!
Well, all I can do is explain why I don't use goto. If you really feel
you *have* to use goto, sure, go ahead.
Regards,
Evert Glebbeek
- Raw text -