Good software craftsmanship also almost never requires global variables.
Instead, you should be thinking about limiting a variable's scope to just the part of the program where it's needed. Look at each of your global variables, and see how much of your program they span. If they're actually only used in a dozen lines, then just have them exist for that scope.
About the only thing that might need to be global is some sort of configuration hash, but even then it's better to pass each routine the information they need, rather than have the routine grab the information from a magical, invisible global variable.
And that's the problem with global variables -- stuff gets magically added and changed, and it's tough to track down where that actually happened when 'something weird' starts to happen. Global variables are probably a rabbit hole you don't want to go down.
Update: Change 'also' to 'almost'. Language brain fart.
Alex / talexb / Toronto
Team website: Forex Chart Monkey, Forex Technical Analysis and Pickpocket Prevention
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
In reply to Re: global variables vs global hash
by talexb
in thread global variables vs global hash
by swoop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |