Page 1 of 1

"Local" and "Local Static" Variables

Posted: Tue Sep 16, 2003 9:13 am
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.

Posted: Tue Sep 16, 2003 9:48 am
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

Posted: Tue Sep 16, 2003 10:00 am
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! :)

Posted: Tue Sep 16, 2003 5:12 pm
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..