Unpopularity of global variables - why?
gandalf at doctorTimothyMiller.com
Fri Oct 12 19:50:11 EDT 2012
On Oct 12, 2012, at 2:25 PM, Bob Sneidar wrote:
> Across ALL stacks in the IDE. That is the rub. If you only work on one application at a time, well and good. But what about library stacks? What about plug-ins? Use as a global something a plugin also uses as a global, and you could really begin to screw things up royally.
That's all true.
On the other hand, I use a complex set of stacks, but I don't use library stacks, plug-ins, etc. Also, the stacks are only for my own use. If something goes haywire, it's my job to fix it.
Sometimes I'm using a dozen or more globals at once. I consistently put empty into all unused globals when a script starts. In my scripts, globals are presumed un-used unless proven otherwise. At the end of scripts, I consistently put empty into all globals when I don't need them any more. If I'm using several globals, I write a handler just for the purpose of clearing all un-needed globals. When perfecting a script or stack, I look at the variable watcher to make sure I don't forget to clear un-used globals. I keep a list of all my globals (in the global-clearing handler), and avoid using local variables with the same name, even if, in theory, I can get away with it.
Works for me. Never had a problem. (I've learned to use custom properties. That works too, and there are other alternatives to globals.) The simplicity of a global concords with my simple skills and simple brain.
Maybe Graham works the way I do. If so, it's not so easy to see why globals are frowned upon.
More information about the Use-livecode