Semantics of Set>>new in Squeak 3.9 -- To initialize or not to
initialize?
nicolas cellier
ncellier at ifrance.com
Tue Apr 4 20:03:23 UTC 2006
Le Mardi 04 Avril 2006 20:47, John Pierce a écrit :
> Hi all,
>
> I am looking at the "new" class method in Squeak 3.9 (and maybe prior
> to that). It appears that most classes implement "new" as:
>
> ^ self basicNew initialize
>
> which is implemented in Behavior. But the "Set" class re-implements
> "new" and does not invoke initialize.
>
> Is this behavior intended? I had a few classes that derive from
> Dictionary and used to work without calling initialize. Now I must
> explicitly invoke the constructor.
>
> Is this lack of congruency the desired behavior?
>
> John
>
Well, a lot of indexable-like classes do implement #initialize: , and a few
implement #init: (Set and some subclasses of it, and also SharedQueue).
Sure, it would be more uniform and highly desirable to rename #init: into
#initialize: , but that said, we can say that the initialization function
does exist in Set (and thus Dictionary).
So there are two possible implementations of new:
The one in Behavior for classes really declared as variableSubclass
(self basicNew: n) initialize
The one in other classes, faking an indexable behaviour, but implementing this
behaviour indirectly by the mean of an indexable instance variable
(self basicNew) initialize: n
Note that since #initialize: has no default implementation in ProtoObject, it
rarely super initialize:, but if you subclass, you'd rather call super.
Depending on where you are subclassing, you might have to define either
initialize or initialize: in your subclass, and i think that it is tolerable.
We just should rename this init: method...
Nicolas
More information about the Squeak-dev
mailing list
|