About KCP and automatic initialize

Martin Wirblat sql.mawi at t-link.de
Mon Sep 15 10:34:20 UTC 2003


>Sorry, but its part of the Smalltalk conventions to make new send 
>initialize (see the Kent Beck book about Smalltalk best practice 
>patterns). 


Nouri,
would you agree that the _general_ Smalltalk convention in reality 
( implementations, ANSI ) is that #new is not sending #initialize? 


>>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, ...)...


It is even more silly to explicitly call a super method and not to 
check on what it does, and yet as you found out, it happened 2 or 3 
times even in the standard image. Now have a look how often 
#initialize is send not during creation times and you will see that 
the semantics of #initialize in reality is not what your idea is 
implying: that it is only for creation. Practically speaking, it is 
not silly to think #initialize is part of and ONLY part of creation. 

To pop up warning-messages to prohibit the programmer from making some 
special mistakes out of a myriad of possible mistakes does not help. 
I guess this new-warning-dialog is more confusing than helpful for a 
beginner. 

An initialize-warning-dialog would be unhelpful too for beginners, 
annoying for others and hmm.. an indication for a wrong design 
decision? ( why do we have to pop up warnings for every method we want 
to write? is this a bad programming language? ). 

Furthermore you can turn your argumentation around: If you believe in 
warnings, it may be a better idea to remind the programmer with the 
new-warning-message not to double-send #initialize. 

Regards
Martin




More information about the Squeak-dev mailing list