About KCP and automatic initialize

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Sep 10 04:32:07 UTC 2003


On further reflection, it seems to me that people *ought* to think
carefully about initialising *each* class they write; a kluge in the
kernel that makes it especially easy to do the wrong kind of initialisation
doesn't sound like much of a help.

First off, the use of lazy initialisation means that many of the classes
I write would have no use whatever for an #initialize method.  Calling
one would just slow them down.

But second, the classes where I *do* need to initialise something typically
require at least one argument to say how to initialise.  Perhaps it's my
design style, but I really don't like setting things up so that clients
have to do
      x := HisClass new.
      x addEyes: 3.
      x giveName: #Triops.
      x lickIntoShape
I'd much rather they did
      x := HisClass newNamed: #Triops withEyes: 3.
A good example in the system would be
    AliceActor newFor: anAliceWorld
which calls #initializeFor:, not #initialize.

I've forgotten, is there any reason to prefer
    ^super new initialize
to  ^self basicNew initialize
The latter has the advantage of not repeating super initialize.



More information about the Squeak-dev mailing list