Avoiding Global Variables - revUp 93

Robert Earp bob.earp at ashford.ca
Sat Jun 5 13:33:46 EDT 2010


As I'm a bit behind on my reading, this may have already been  
discussed and if so I apologize, but I can't find any references to  
Oliver Kenyon's article titled "Avoiding Global Variables" in revUp  
issue 93.

Firstly, I'd like to thank Oliver for his time and effort putting the  
article together, even though I have concerns with the content.

I'm concerned that readers of the article, especially new people to  
Rev and scripting, will now stay away from global variables, which  
would be a shame as they are extremely valuable.   I believe the crux  
of the Olivers concerns about global variables is one of scripting  
practices and project documentation, rather than global variables  
themselves.

There's absolutely nothing wrong with global variables, in fact I much  
prefer them to other means of storing data especially when wishing to  
access that data across multiple stacks and/or locations.  Global  
variables are truly global, and as such save an awful lot of  
addressing problems which ends up in simpler script.  But I do agree  
in using custom properties of objects, or groups, when the data truly  
refers to something associated with the object/group.

For example, the number of passengers in a group named myAircraft  
would better be stored in a property of myAircraft, and named  
something like numPassengers.  It makes scripting to the data very  
logical and almost self documenting.  Also, doing it this way the  
myAircraft group can be duplicated, renamed whatever, and the script  
references essentially stay the same.  Well, apart from referring to  
the additional aircraft name!!

Olivers concerns are real, however they do not need to be solved by  
giving up on one of the most valuable assets in revTalk (or other  
languages for that matter).  The solution is that we need to manage  
ourselves better, and most of us don't want to do that.  It's also  
something that does not get much emphasis in education today.  Not  
wishing to sound like an old fart, which I am, when saying this ;-)

Global variables vs. local variables and custom properties is a  
subject that has been discussed as long as I've been scripting, and  
that's a few decades.  Some great words have been written about the  
subject and the associated one's of scripting practice and  
documentation.  There are a number of papers written on all of this  
and some tools that help manage things.  I seem to remember Richard  
Gaskin having a tool to list all variables in a stack, for example.

One key item that is so simple it seems to get forgotten, and that is  
to name the variables and the properties with something meaningful.   
That means "meaningful" to others, and of course yourself when looking  
at a project in months or years to come.

I'm sure a lot of the readers wrestle with this management problem on  
a constant basis, but maybe it's something we need to remind each  
other of now and again.

Thanks everybody for helping everybody develop in Rev.  I wish we had  
governments that were the same ;-)

best, Bob...


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
www.ashford.ca  www.cabinsimulators.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Robert J. Earp
Ashford Technologies Inc.
18059 21A Ave, Surrey
British Columbia.  V3S 9V7
Canada

t: (+1) 604 541 1662
f: (+1) 604 541 1686




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
www.ashford.ca  www.cabinsimulators.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Robert J. Earp - President
Ashford Technologies Inc.
18059 21A Ave, Surrey
British Columbia.  V3S 9V7
Canada

t: (+1) 604 541 1662
f: (+1) 604 541 1686







More information about the use-livecode mailing list