New | BasicNew What is the Difference?

John-Reed Maffeo rlpa80 at email.sps.mot.com
Tue Jan 5 19:14:34 UTC 1999


Ralph Johnson wrote:
> 
>         Behavior New
>         Behavior BasicNew
>         Behavior New:
>         Behavior BasicNew:
> 
> First, they are "new", "basicNew", etc.  Capitalization is important.

Oops! I knew that. That is what happens to me when I stay up programming
rather than going to bed at a reasonable time.
> 
> Most programmers will never use basicNew and basicNew:.  new is used

The reason that I asked the question is found in the Form class methods
extent:depth and extent:depth:bits. They use basicNew rather than new,
and I couldn't figure out why.

Form class inherits new and basicNew from Behavior, so it seems like
it would be more appropriate for the methods to use new rather than
basic new.

> for a normal class, while new: is used for a collection or some other
> class with an indexible part.  Array new: 10 returns an array of length
> 10.  OrderedCollection new: 10 returns an OrderedCollection of length 0
> but with space for 10 elements without growing.  In general, new returns
> an object with every variable initialized to nil, unless you redefine
> it, such as to initialize variables.  Only a few classes redefine new,

In my Squeak 2.3b image (virgin), there are 77 implementors of new and
13 implementors of new:

They are used for a variety reasons and coded in a variety of styles.
The analysis of which is left as an excercise for the student.

> but it *does* get redefined, and that is why basicNew was defined.
> Stream redefines new to generate an error message.  This prevents
> people from getting an undefined Stream.  A subclass might define a
> new class method "on:" to create instances.  This method will have
> to call "new", but "new" was redefined by its subclass.  So, how can
> it call "new"?  The secret is that Behavior defines basicNew to be
> the same as new, and you are never supposed to redefine basicNew
> (or any other methods with basic as a prefix).  So, if you need to
> call the original version of "new", and "new" is redefined, call
> basicNew instead.
> 
> -Ralph Johnson

Thanks for your comments,

John-Reed Maffeo





More information about the Squeak-dev mailing list