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: John W Baxter <email@hidden>
- Date: Sat, 7 Apr 2001 08:20:01 -0700
At 4:31 -0600 4/7/01, Ehsan Saffari wrote:
>
On Fri, 6 Apr 2001 22:09, John W Baxter <email@hidden> wrote:
>
>
>
>At 16:22 -0700 4/6/01, Paul Berkowitz wrote:
>
>>Well, this will be interesting. There are people, including some real
>
>>experts here, who believe that globals are dangerous, but I've never
>
>>understood why. It seems to be something taught in computer classes that
>
>>stick with people to the ends of their lives, just like the things that your
>
>>parents told you were "bad" when you were 5 years old. I've been wondering
>
>>if it's really no more than a superstition and habit, since I've never seen
>
>>anything bad result from using globals.
>
>
>
>It's taught in computer class because experience in the days of routine use
>
>of globals showed it *could* be a nightmare.
>
>
I've never attended a programming class, and I considered the chance of
>
someone else running another script concurrently that would use the same
>
global name as one of mine extremely remote.
>
>
So would the use of a property instead of a global be the answer,
>
initialized at the start of each run?
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.
Global doesn't mean "every script can see it" but rather "everything in
this script can see it."
John (who has removed an erroneous assertion and a wonderful example
purporting to demonstrate it....whew!)
--
John Baxter email@hidden Port Ludlow, WA, USA