[Newbie] Morph class>>new

Nevin Pratt nevin at smalltalkpro.com
Wed Apr 16 12:44:55 UTC 2003



Richard A. O'Keefe wrote:

>Concerning instance creation,
>if if Object has
>
>    new
>        ^self basicNew initialize
>    initialize
>        "do nothing"
>
>then many classes would not need to define #new at all.
>
>
>  
>

Richard,

Have you (or anybody else) done this with Squeak?  I'd be interested in 
your results.

Just some additional data points:

1. Objective-C has always done this (so that #initialize is always 
automatically called).

2. It is a *very* common pattern to see folks create an abstract base 
class (as a superclass of their own classes) that does this.  If the 
Object class took care of it, we wouldn't see people creating such 
abstract base classes.

3. At least one VisualWorks engineer (Alan Knight, I think, but I might 
be remembering wrong) is advocating adding this pattern to Object in 
VisualWorks.

However, on the downside:

4. I tried to add this pattern to Object in VisualWorks many, many years 
ago, and it broke some existing code (the GUI Painter for example, if I 
remember correctly, had some problems).  So, I gave up on trying to add 
it to Object, and haven't tried again since with any other dialect. 
 Seems anymore I find myself *expecting* it to break stuff if I try it, 
so I just don't try it.

In summary:

I think it would be a general improvement to have this pattern exist in 
Object, but wouldn't be at all surprised if doing it broke stuff, even 
though it looks at first blush like a rather benign change.  So, if it 
is done, I would recommend more extensive testing than what you might be 
inclined to suspect was necessary.

Nevin




More information about the Squeak-dev mailing list