Pressures for Substantially New Squeaks

Reinier van Loon R.L.J.M.W.van.Loon at
Sat Feb 13 16:05:32 UTC 1999


I've been following the name space discussion for a while and I do not
really understand the need for something like that. I.e. I solve the
"problem" as follows:

1) add the following source as instance method to Object
classAt: aSymbol
    ^ Smalltalk at: aSymbol

2) by overriding this method at the correct places you can prevent name
clashes and more

Example 1:

    ThingLabObject>>classAt: aSymbol
        ^ self classes at: aSymbol ifAbsent: [ super classAt: aSymbol ]

In this particular example the ThingLab classes come before any global

Example 2:

    SomeOtherObject>>classAt: aSymbol
        ( aSymbol beginsWith: 'ThingLab' ) ifTrue: [    ^ ( super classAt:
#ThingLabObject ) classAt: aSymbol ].
        ^ self classes at: aSymbol ifAbsent: [ super classAt: aSymbol ].

In this example any symbol prefixed with ThingLab redirects to

This works for me in all the projects I've been doing.

A more elaborate solution:

IMHO all these name spaces are just other (System)Dictionaries. So, it would
be even better to add a method systemDictionaries ( or namespaces ) to
Object which answers all available system dictionaries, like in:

    ^ Smalltalk at: #systemDictionaries ifAbsentPut: [ Dictionary with:
 Assocation key: 'Smalltalk' value: Smalltalk ) ].

then we can rewrite example 2:

    SomeOtherObject>>classAt: aSymbol
        ( aSymbol beginsWith: 'ThingLab' ) ifTrue: [    ^ ( self
systemDictionaryAt: 'ThingLab' ) at: aSymbol ].
        ^ self classes at: aSymbol ifAbsent: [ super classAt: aSymbol ].

Now, if we can discipline our selves to always specify which dictionary to
use the problem can be solved at Object level.
Example (an actual problem for me when working on ThingLab)

    thingLabSliderClass := self classAt: 'Slider' in: 'ThingLab'.
    morphicSliderClass := self classAt: 'Slider' in: 'Morphic'.

and classAt:in: like this

    Object>>classAt: aClassName in: aDictionaryName
        | vocabulary |
        vocabulary := self systemDictionaries at: aDictionaryName asSymbol
ifAbsent: [ nil ].
        vocabulary isNil ifTrue: [
            aDictionaryName asSymbol = #Smalltalk ifFalse: [ ^self classAt:
aClassName in: 'Smalltalk' ].
            self error: 'Class ' , aClassName , ' not found in ' ,
aDictionaryName , ' or Smalltalk'.
        ^vocabulary at: aClassName asSymbol

It's like a file system which only supports directories at the root. This is
a simple but effective first version. Later on, the agument aDictionaryName
can be changed to allow URL's and other more elaborate dictionary name
formats. But the protocol stays the same: classAt:in:.

Furthermore, I like to add that I consider it bad style to reference class
by hard coding their names. Okay, performance is enhanced in this way and
one can easily find methods which reference class X but... when there is a
circular reference you can't get your code to file in. And when you change
the class name... Anyway, this is more or less inspired by working with the
Smalltalk Link Libraries of VSE (it is a killer to reference classes by
name). You first have to load in the other libs before you can load in the
desired lib...


More information about the Squeak-dev mailing list