About removing global variables

lex at cc.gatech.edu lex at cc.gatech.edu
Mon Nov 29 05:30:36 UTC 2004


Ned Konz <ned at squeakland.org> wrote:
> Date: Sun, 28 Nov 2004 10:49:00 -0800
> From: Ned Konz <ned at squeakland.org>
> Subject: Re: About removing global variables
> To: squeak-dev at lists.squeakfoundation.org
> reply-to: The general-purpose Squeak developers list <squeak-dev at lists.squeakfoundation.org>
> 
> On Sunday 28 November 2004 4:03 am, stZphane ducasse wrote:
> > my point was simply that we have 12 global variables in the system and
> > that we all know that global variables is not a
> > so good ideas so I was thinking that this would be nice to remove them.
> 
> Actually, at least three of the global variables are (or could be) class 
> variables in Morph. These are:
> 
> World
> ActiveHand
> ActiveWorld

Sounds good to me, provided you figure out a way for World to be
accessible in workspaces as well.  I don't care about ActiveHand and
ActiveWorld.  I don't even know what ActiveWorld is....

Still, I don't see a reason to take the attack on globals as more than a
guideline.  It's a good guideline, but we've already been following it. 
12 sounds like a good number to me.  That's one variable for each of a
small number of fundamental concepts in the system.  Fundamental
concepts *should* be accessible by just typing the name of it.  Sure
global variables have problems, but that's all we have right now.  And
anyway, if a concept is global and widely used and singleton, isn't that
just what a global variable is for?  Squeak has one Display.  Thus, why
not make it a global variable?

Maybe a good alternative would be to move them into pool dictionaries or
some other kind of namespace?  Then anyone who imports the "Morphic"
namespace has access to World, and others can leave it alone.  Anyone
who imports the "LowLevelDisplay" namespace has access to Display and
Sensor.  (And before doing this, please make workspaces auto-import a
customizable list of namespaces.  If we lose the ability to do things
like "World flash", then we are taking a step backwards!)

As food for thought, notice that you can keep adding more abstraction
indefinitely:

	World flash

	World current flash

	Flasher flash: World current

	Flasher defaultInstance flash: World current
	
	| flasher |
	flasher _ Flasher new.
	flasher flashingAlgorithm: #default.
	flasher flashTarget: World current.
	flasher beginFlashing.
	

In short, let's not to pretty up the language at the expense of ugly
programs.  Squeak is supposed to be programmed, not just talked about,
and there will be tradeoffs that are necessary.

-Lex



More information about the Squeak-dev mailing list