[Pharo-project] Auto create new and initialize methods for new class?

Igor Stasenko siguctua at gmail.com
Sat Jun 16 17:04:24 EDT 2012

In fact, a new instance IS initialized by VM, by putting nil values to each slot
and zeroes in case of byte array.
What happens next, when you sending #initialize? Yes, you rewriting these values
by own, which sound like initial nil-out of all slots was unnecessary.
So, in some cases it could be less wasteful (in terms of performance)
to just make a copy
of existing instance:

   preinitializedInstance := self basicNew initialize.

   ^ preinitializedInstance shallowCopy.

and this actually a bit faster , except from, of course if #initialize
also creating new objects,
then cannot avoid extra initialization step.

Also, often you cannot fully initialize object using just #initialize
because it requires some additional
arguments to initialize properly. For that many languages having
so-called constructors,
where you cannot obtain an instance with not properly initialized
state because you have to use
constructors when creating new instance.

Best regards,
Igor Stasenko.

More information about the Pharo-dev mailing list