"Local" and "Local Static" Variables

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

"Local" and "Local Static" Variables

Post by dmoc »

Here's a tip: If you are starting a project that is likely to grow to any reasonable size, group all your global variables into one (or several) global *structure* variables. The disadvantage of adding "myvar\..." all over the place is far outweighed by avoiding having to hunt down bugs because you forget you are already using a global variable elsewhere. Which leads to my request: PB would be more managable if in procedures it supported true "Local" variables which do not effect any global use of same named variables. Add a "static" option to preserve values between calls and now you don't even have to worry about clashing with global variables.

@Fred: I'm sure you know exactly what I am requesting without all the above. The description is for the benefit of others who may not have come across these options in other languages.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

btw: Other suggestion.
I have splittet my programms in serverall files and so it would be usefull, when a variable only exist in this file, something like

ProtectInFile var
GlobalInFile var

GPI
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Re several files: my current project is split into about 16 files. Yes, your suggestion would be useful but I suspect PB would end up having to support name spaces. I'd settle for "local" and "local static" for now... oh and a debugger that actually worked across multiple files. Now that would be a time saver! :)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Local already exists: it's 'Protected'. About Static, it will be implemented very soon as it's really needed.

GPI: the idea to make file only scope variables is interesting, it would allow to do JAVA like package feature.

May be something like this:

Code: Select all


Global a,b ; a and b are global everywhere

Package Mod1

Global a,b ; Global only in the Package Mod1 and very global values aren't modified at all

Package Mod2

Global e,f ; Global only in the Package Mod2

Of course you could put the same Package word in several files, so it will allow to shared global variable trough files too. Just a tough..
Post Reply