What's wrong with Globals?

Richard Gaskin ambassador at fourthworld.com
Sat Mar 31 01:50:36 EDT 2007


Mark Wieder wrote:

> Globals are what I usually think of as the way people start out using
> variables until they learn better ways. 

This raises the central question:

   If using globals are to be seen as a Very Bad Thing,
   why is it that some of the world's most experienced programmers
   keep designing languages that support them?

:)

Nearly any attribute of any entity can have both good and bad effects. 
I believe the same is true for global variables.   While I agree with 
every point you made, most of them also apply to custom props and some 
can even be helpful features of globals.

I tend to agree that HyperTalkers are especially prone to using globals 
in places where alternatives may do more for them.  But in HyperCard 
that's all they had, there were no custom properties or script-local 
variables.  Who could blame the Bedouin for not knowing how to swim?

But on balance, I believe there's a good reason most languages have 
globals in their design.  When you need 'em, you need 'em.

The tough part is knowing when you need 'em.


Maybe some brave soul with time on their hands can fill in this matrix:


                      Best For...       Not So Good For...
                     -------------     --------------------
           Globals

            Locals

     Script-Locals

Custom Properties



If anyone wants to take a stab at something like that I'll gladly post 
it at revJournal....

-- 
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com



More information about the use-livecode mailing list