About KCP and automatic initialize

Roel Wuyts wuyts at iam.unibe.ch
Tue Sep 16 10:04:14 UTC 2003


On Monday, Sep 15, 2003, at 11:12 Europe/Zurich, Martin Wirblat wrote:

> Noury Bouraqadi <bouraqadi at ensm-douai.fr> wrote on 15.09.2003 08:50:52:
>
>> (2) If by default new does not call initialize (as it is now in
>> Squeak), people can do mistakes. I found 2 or 3 subclasses where the
>> #new method have bee redefined to "super new initialize" while the
>> #new of the superclass does the same thing (i.e. sending initialize
>> to the newly created instance). So, there is a duplicated call of
>> initialize that may lead to undesirable side-effects.
>>
>> Observation (1) is a prove that people do really need having new
>> trigger initialization. By not providing it, we make people do
>> duplicate code. Observation (2) demonstrate that this duplication not
>> only is space consuming, but its error prone....
>> So, my conclusion is that *we need* to have new trigger
>> initialization!
>
> It is even more error prone if #new is calling #initialize by default.
> It is by far more likely that one forgets OR does not know at all that
> #new 'silently' and against all Smalltalk conventions sends
> #initialize, than that one forgets to have a look at the super
> implementation if he calls it.

That is general Smalltalk practice to have a look at yoour superclasses 
to see whether one of your superclasses already implement it... This is 
the same for such an initialize method. One can also forget to look at 
#postCopy, or forget a 'super postCopy', or directly override #copy for 
adding copying behaviour (been there, done that).

>
> There will be made many mistakes by those who are not accustomed to
> this behavior.

As is with most changes. So should Squeak come to a standstill for the 
sake of backwards compatibility?

>
> Additionally I think it is really easy to forget about it: If one
> plans to use #initialize for resetting or preparing later on etc,
> rather than for creating, it may not come to ones mind that during
> creation it is called too.

Calling such a 'reset' method 'initialize' is not good... it is a hack, 
and that is what you pay for it. At least, one should implement a 
method #reset that just calls 'self initialize' - that way it is clear 
that in that case the reset is just an initialize.


Roel Wuyts



More information about the Squeak-dev mailing list