About removing global variables

lex at cc.gatech.edu lex at cc.gatech.edu
Sun Nov 28 15:54:44 UTC 2004


It would be good to use class variables of Object instead of globals,
just so that we can have one fewer kind of variable.  The global
variables would then be the class variables of Object.  That's a pretty
nice way to go: it simplifies the language while having no practical
cost that I can think of.

It would also be possible to invent new classes and stuff the current
globals into them.  So it would be "World current" instead of "World". 
But that actually seems to be a step backwards.  If I want the current
world--an important concept for Morphic programmers--why should it
require more than one word to name what I want?  Maybe you are thinking
that when I write "World", the semantics should be other than a simple
variable lookup like right now?  Well, if that ever happens, then let's
revisit the idea.  Right now, variables are the only way in Squeak to
get one-word names for things.

I do not understand the multiple types issue that you bring up.  I agree
with Trygve that it is nice to have a *general purpose* mechanism for
mapping names to the *objects* they denote.  It is hard to predict what
individual words we would like to be globally acceptible in the future,
but notice that we already have some (World, Smalltalk, Sensor, Display)
which do not denote classes and which have been proven convenient over
the years.  I don't want *any* of these to require multiple words to
specify, and so I am not convinced that only classes should be named at
the global scope.  You mention testing for whether something is a class
or not, but when should this happen?  For one, there are already plenty
of methods for navigating the class hierarchy; for another, they can
just as well be implemented with code like "ProtoObject
withAllSubclasses" instead of by rooting around in the global variables.

So in short, reimplementing globals as class variables of Object: good. 
Replacing all globals with a two-word designation: bad.  Yes, we want
the language design to be pretty and concise, but we should also strive
for things *written* in the language to be pretty and concise.

Lex



More information about the Squeak-dev mailing list