Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Removing these gotos

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Jun 2008 04:10 Edited at: 9th Jun 2008 04:32
I'm trying to convert some code from DBPro over to DGDK. It's Evolved's lightmapping code, and it uses a very funny goto thing that's rather tricky to get rid of.

Here is the relevant structure:


I can't exactly put a loop in it. Anyone got any ideas?

P.S. Recursive functions wont work because there're variables and other data elsewhere in this function that are being used.

Thanks


[edit]

OK, I figured it out. I can just set 'i' back to 0 and use 'continue' to go back to the beginning of the loop (since the label is right before it anyway).

Don't you just hate that Zotoaster guy?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Jun 2008 05:27
Have you looked at the switch/case/break statements?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Jun 2008 16:38
How would that help?

Don't you just hate that Zotoaster guy?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Jun 2008 18:51
It was more or less a guess without seeing what kind of conditions you were dealing with.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 9th Jun 2008 19:23


As far as the labels go, you're going to have to make them functions and pass in the value by reference. Might be a good idea to pass them in 'const' so that you don't accidentally change anything.

Cheers.


Tux is my guildmaster.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Jun 2008 19:45
Well, doesn't matter. In my edit I explain how I fixed it. Besides, I've given up trying to convert the code. I didn't mind one or two gotos, but it just got too much, and I became all spaghettified I didn't wanna spend this whole week trying to copy it and find it doesn't work anyway, which is likely. DarkLights, here I come

Don't you just hate that Zotoaster guy?
MayoZebraHat 1979
16
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 10th Jun 2008 14:21
Your way is probably the best fix.

Goto syntax works in C++ as well with lables like "label:" and then "goto label;"

The problem is that people will flip you off, throw things at you, and never talk to you again if you use them. Including myself. Then again no one can see your source once you compile it! I dunno what it looks like disassembled...
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 10th Jun 2008 18:02
Instead of gotos, use OOP!

Or use gotos...DarkGDK really wants to be a BASIC program with all its gotos and everything...

Don't let the masses tell you how to code. There's nothing wrong with using goto, especially if you're used to it. You could be the "goto guy!"
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 10th Jun 2008 18:42
Gotos turn good working code into this:


A good program can easily throw an exception because of this useless function. If your making a game, gotos will kill it. NEVER use gotos, unless you are making some MS-DOS app.

I would rather have a for loop in a function and have the function call itself if a condition is met.

dbPrint ( "Sig" );
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Jun 2008 18:46
Quote: "There's nothing wrong with using goto, especially if you're used to it. You could be the "goto guy!""


I used to program in a langauge called CPL, which was a fairly limited language for a niche minicomputer my employer was using. When I started programming it it was called CPL5. I had to use goto and gosub (or some form of it) exclusively. Then CPL6 came out and it had for structures and while structures and a whole lot of control loops. Once I started using those it made my tasks a lot easier. It's not that there was anything inherently wrong with goto, but it made program flow hard to visualize and created, for me, the necessity of duplicating some code to make sure something got done under THAT circumstance.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Jun 2008 19:51
Quote: "There's nothing wrong with using goto, especially if you're used to it"


I used to use goto, for like a whole day when I first started If anything, I'm no "goto guy". I'm the "guy who's obsessed with perfectly structured code". I am using OOP btw, but it still doesn't help replace the gotos inside a function.

Try and visualise a tree of classes and functions, everything perfectly structured, where you can traverse from the start of the tree down through classes and functions to reach a certain one. That's what I call organised. Once you introduce goto you have a jump from one bit to a completely unrelated place, and I personally think that screws that up. It doesn't satisfy me much, and I bet you could get a whole bunch of stack problems too.

Don't you just hate that Zotoaster guy?
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 10th Jun 2008 20:03
Goto has its place in coding. For example, in some emulator cores or interpreters. Its just very unlikely anyone here will be in a situation where they need to use it and if you do use it then do it properly and make sure you know what it is you're doing.

avoid it when possiable.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Jun 2008 01:38
Quote: "Gotos turn good working code into this"

This sounds like a statement from the view of an inexperienced programmer. My version of that statement would go gotos can turn good working code into this.

dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 12th Jun 2008 00:14
Yeah, my bad, sorry. If you know how to use gotos, then your OK. But personally, I don't and I made a statement from my perspective (gotos turn your code into this). Back when I was taking C++ classes, I had made a calculator program that used a lot of gotos. It seemed to work, but the more I used it, I realized that is sometimes added dynamic data etc. Since that day, I hated gotos. So from my perspective, gotos turn code into spaghetti!

You don't need to know how to use goto to be an experienced programmer. I will most likely never use it.

But you have a point there.

dbPrint ( "Sig" );

Login to post a reply

Server time is: 2024-11-20 13:43:31
Your offset time is: 2024-11-20 13:43:31