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 / An example of default parameters

Author
Message
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 4th Dec 2008 02:34 Edited at: 4th Dec 2008 02:35
I wrote this today. In effect, it's a simple boolean variable with a function wrapped around it to easily set or get its contents.

Header:


Source:


So the following are all valid calls:


Any feedback?

~you can call me lantz~
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Dec 2008 05:57
I'm not sure what you're asking?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 4th Dec 2008 16:53
Seems like that should work, but I can't help but ask why you need that function. It seems like you'd be fine with just the variable.


My site, for various stuff that I make.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 5th Dec 2008 06:35
@Lilith:

I guess that's good enough .

@SunDawg:

It was simpler than working with a SetPaused() function in another file and a global variable in my main file. And you can call it another form of encapsulation.

Can you?

~you can call me lantz~
veltro
User Banned
Posted: 5th Dec 2008 07:29
Wasn't it simpler (and faster) to have a variable and check it?

declare


check


set
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 5th Dec 2008 23:08
I agree. Using a boolean as the data type avoid the possibility of the programmer erroneously passing the wrong parameter type. Otherwise, polymophistically you can just have two functions. One with no argument to pass back the current status and the other to set the state to whatever the programmer finds necessary

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: 6th Dec 2008 02:10
You're just as well defaulting it to 0.

elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 11th Dec 2008 19:41
then i guess this is no more than a poor example of the title.

~you can call me lantz~
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th Dec 2008 04:07 Edited at: 12th Dec 2008 04:08
LOL.... No its a lesson in programming is what it is... and I think the intent was cool - but the explanations would un complicate it. If you must encapsulate... make the isPaused thing a private variable.. with methods to set/access it... but for a simple boolean... like "paused" ... that's one of those kind of variable I don't mind having in a structure I purposely make visible globally.... I mean... One stop shopping ... I know globals are considered bad but they aren't if used properly... sparingly....

I usually will set up a structure... as a "holder" for things that are global.. so they are at least grouped together:

(pseudo)
struct TMyGlobals{
bool Paused_b;
int Lives_i;
}

Then I'd make the struct accessible (this is slick with intellisense of course)

g.Lives_i = 3;
g.Paused_b = true;

--Jason

Login to post a reply

Server time is: 2024-09-30 13:13:25
Your offset time is: 2024-09-30 13:13:25