Keyword 'Global' is not really useful ... use Shared

Everything else that doesn't fall into one of the other PB categories.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: Keyword 'Global' is not really useful ... use Shared

Post by NoahPhense »

PB wrote:Do you really want all that hassle?
Yeah man... don't hassle the hoff...

- np
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Re: Keyword 'Global' is not really useful ... use Shared

Post by Amiga5k »

PB wrote:> If you use Global very often (You like it?) it seems to be a bad design of your code

No it's not. I use it for variables that NEVER change, such as appname$ that
holds the name of the running exe.
Isn't another name for a variable that never changes a "Constant"? ;)

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Re: Keyword 'Global' is not really useful ... use Shared

Post by Henrik »

Amiga5k wrote:
PB wrote:> If you use Global very often (You like it?) it seems to be a bad design of your code

No it's not. I use it for variables that NEVER change, such as appname$ that
holds the name of the running exe.
Isn't another name for a variable that never changes a "Constant"? ;)

Russell
@Amiga5k not really.
A Constant can't be defined by a variabel, whereas a global can be, and at runtime and stille never change after that, if you like.

best Henrik
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Keyword 'Global' is not really useful ... use Shared

Post by PB »

> Isn't another name for a variable that never changes a "Constant"? ;)

Yes, but only when the variable's value is already known. Observe:

Code: Select all

#appname=ProgramFilename()
Image
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Well, there you changed it (it was null when the program started, now it's "PureBasic1.exe" or something).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> you changed it

Technically: yes, of course a variable will change once you give it an inital value.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

And you did say that you would "Never" change it... ;) Just messing with ya here, but there is a subtle difference. It could, however, be useful to allow Constants to be defined initially with a variable - under certain rules of course (such as the example given). But I suppose in that situation you would just use a Global. :wink:

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

I'm not sure I see how a constant can be assigned a variable value.

Maybe special constants could be created such as #PB_ProgramFileName, but they would not be real constants. PureBasic would have to do some hidden initial code to assign the value to the Psuedo-Constant. And in such a case there would be no real gain for the programmer or the program over using the Global approach as PB outlined.
Dare2 cut down to size
Post Reply