About KCP and automatic initialize

Noury Bouraqadi bouraqadi at ensm-douai.fr
Mon Sep 15 09:20:17 UTC 2003


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. 
>  
>
Sorry, but its part of the Smalltalk conventions to make new send 
initialize (see the Kent Beck book about Smalltalk best practice patterns).

>There will be made many mistakes by those who are not accustomed to 
>this behavior. 
>  
>
Its just a matter of documenting/learning. New users make mistakes... 
That's natural.
Note however that avoiding this mistake can be enforced by the system. 
When you
redefine #new in Squeak, an notification window appears saying that its 
"dangerous" and
whether this is what do you want. We can extend this comment by telling 
about the initialisation
pattern.... Hence, people can *not* forget it.

>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. 
>  
>
I'd rather suggest "reset" for a method doing resets... It reflects 
better what a such method does...
One should keep "initialize" for initialization...

Any way, we can not avoid people doing silly things (bad names, bad 
desings, ...)...

-- 
------------------------------------------
Dr. Noury Bouraqadi - Enseignant/Chercheur
Ecole des Mines de Douai - Dept. G.I.P
http://csl.ensm-douai.fr/noury

European Smalltalk Users Group
http://www.esug.org 

Squeak: an Open Source Smalltalk
http://www.squeak.org 
------------------------------------------





More information about the Squeak-dev mailing list