Ways of new

Yoshiki.Ohshima at acm.org Yoshiki.Ohshima at acm.org
Tue May 6 19:02:15 UTC 2003


  Hello,

At Mon, 5 May 2003 23:10:43 -0700 (PDT),
Anthony Adachi wrote:
> 
> Derek Brans wrote:
> >  I think 'super new initialize' runs the risk of
> initializing the object
> >  more than once
> >  (eg., if the super class also defines new as 'super
> new initialize', you
> >  are calling initialize at least twice)
> 
> If that is the case is there any reason in particular
> that an author might wish to use 'super new
> initialize' rather than 'self basicNew'?

  There is a resistance to *use* #basic... in your code.  It sometimes
means that your code is not well-factored so it has to bypass a
standard mechanism.  However, in this #new case, I think it is just
fine to use #basicNew because there is *essentially* only one
implementor of it and the behavior is well-understood.

  The resistance to define your #basic... is bigger than to use.  But
there are cases where doing this is better, of course.

  By the way, Aoki-san once suggested that a definition something like

new
    ^ (super new) initialize; yourself

is more intention revealing because it clearly shows that the object
to be returned is the one which is newly created.  At least, if you
want to initialize your object with a method that returns something
other than self, this is a solution.

-- Yoshiki



More information about the Squeak-dev mailing list