About KCP and automatic initialize

Martin Wirblat sql.mawi at t-link.de
Mon Sep 15 09:12:35 UTC 2003


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. 

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

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. 

Regards
Martin 



More information about the Squeak-dev mailing list