Ways of new

Yoshiki.Ohshima at acm.org Yoshiki.Ohshima at acm.org
Thu May 8 07:25:44 UTC 2003


  Anthony,

> >  One of the *reason*, which is merely a hypothetical
> explanation, why
> >  we see many "super new initialize" would be that
> those Smalltalkers
> >  steal code. They really do. The ones written early
> days must be
> >  written in that way, and later people just copied
> the old examples.
> 
> >  Also, again, using methods whose name begins with
> 'basic' has some
> >  dangerous smell.
> 
> Not sure what you mean by that? Also, are you
> referring to redefining 'basicNew' or simply sending a
> message to 'basicNew'? Please explain.

  By this "steal" part, I mean literally.  The nature of Browser tends
to let you copy a method definition from one place to another.  When a
typical Smalltalk programmer find a code which does what he wants, he
just copys the definition and uses it in his own program.

  By "begin with 'basic' part", I mean literally.  Using some method
whose name begins with 'basic' gives me an impression that it is
trying to do something that a *non-meta* code cannot do.  I don't
specifically means basicNew but also other 'basic' methods, too.  One
usually want to use 'meta' features only when it is appropriate.

  Redefining basicNew sounds really *scary* to me.  Calling methods
whose name begin with 'basic' is less scary, but it would make me
think that there might be better way to handle the situation.
Defining a method with 'basic', assuming there is accompanying method
without 'basic', makes me think, too.  This is what I meant by
"dengerous smell'.  (Of course I do use 'basic' sometimes when I think
it is appropriate.)

  Surely 'self basicNew' and 'super new' are semantically different,
but the difference is kind of tiny especially if you are sure that the
superclass(es) is not going to be changed some near future.  It looks
to me that the difference is kind of similar to the difference where
you end the last message sending expression in a block with '.' or
not.  (Maybe too wild analogy, though.)  As I wrote, basicNew has
well-defined behavior and there is virtually only one implementor, so
*calling* it doesn't sounds too bad to me.

  This is my theory, but if one thinks that to avoid 'basic' method is
more important, he uses 'super new'.  On the other hand, if he wants
to avoid potential risk, he uses basicNew.  Someone like me just uses
either one without thinking too much.

> Besides, I just simply wanted to know what was the
> most prudent way to implement a method which overrides
> new for future reference.

  The most prudent one I can think of is:

     ^ (self basicNew) initialize; yourself.

> By the way...
> 
> >  I'm now curious that why you want to know this
> *reason* so badly:-)
> 
> I'm curious, as to why you asked such a question?

  Well, it sounded to me that your question was something like "why a
FileList is pink and a method finder is light blue?"

  It is kind of my mind set, but my general belief is that there are
many things in the world that doesn't have much siginificant *reason*
whay it is in particular way.

-- Yoshiki



More information about the Squeak-dev mailing list