Re: Globals are considered harmful (was Re: Recursion script which doesn't?)
Re: Globals are considered harmful (was Re: Recursion script which doesn't?)
- Subject: Re: Globals are considered harmful (was Re: Recursion script which doesn't?)
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 07 Apr 2001 10:35:14 -0700
On 4/7/01 8:20 AM, "John W Baxter" <email@hidden> wrote:
>
No...properties are essentially globals which are given an initial value at
>
compile time, when used in the main script. The problem with globals isn't
>
that running a different script concurrently could trample on them but that
>
they don't scale well to large scripts (or large programs): it is too easy
>
for the script writer to get confused. A script editor which supports
>
multiple panes would help.
Thinking a bit further about this, and the persistence of globals which
might cause problems:
The thing is: although theoretically persistent, globals have to be set to
be used, otherwise they error as undefined variables. So the next time you
run the script, they are automatically reset to the original setting, and
are thus effectively not persistent. You can't even start out
if someGlobal "" then
--do something
else
set someGlobal to something
end if
like you do with a property, because that will error as undefined as well.
This seems pretty safe to me. The sort of circumstances I can imagine in
which globals would really persist would be one where a global is set in
some handler that isn't run the next time, but some other part of the script
containing the global _is_ run. That would indeed would be a problem. That's
a sort of "messy" setup I don't think I would ever write, but I guess the
"no globals" dictum protects innocent users from messy scriptwriters. OK,
got it, I guess.
--
Paul Berkowitz