globals

mark mitchell cowhead at mac.com
Tue Aug 27 04:37:01 CDT 2002


Rob wrote:

>> Presumably it would maintain a list and then every time you used a
>> variable, it would have to check to see if it was in the list.  But
>> once you added a variable to the list, you would never have to add
>> it again, which would be a nice feature.
>
> Whoa Mark,
>
> That would mean every time one wrote a handler one would have to
> check EVERY local variable name to make sure it was not on the global
> list.  This would include handlers in other people's stacks as well
> as your own.
>

Doesn't Rev already do something like this for the built-in constants 
and properties and what-not on compiling?  I have tried to use variable 
names before which caused the script to fail as the name was already 
'taken' by something.

>
> I was able to replace all globals in my original HyperCard library
> design with locally-declared variables.

Isn't removing the distinction between global and local variables (by 
eliminating one entirely) a little like picking all the raisins out of 
your raisin bran?  You do all this extra work to end up with boring bran 
flakes.  Well, to each his own.  Whatever works for you.

A friendly Australian shared with me off-list the idea of simply making 
all your globals an array, call it myGlobal.  Then you need only declare 
"global myGlobal" at the start of each handler.  Pretty nifty (although 
typing the variable name within each hadler e.g. myglobal[startTime] 
becomes a bit more cumbersome.)

My own habit is to now simply copy and paste the initial global 
declaring line from the previous handler into any new handler I start.  
Keep adding to the line as needed.  The list can get long, but you have 
all your global variable names readily visible (good for Mr. Short-term 
memory).  Using this technique, I haven't made a misspelling or failure 
to declare error in years.

best,

mark mitchell
Japan




More information about the use-livecode mailing list