Adding and removing methods

Brian Murphy-Dye brian.murphydye at mac.com
Tue Mar 16 22:01:46 UTC 2004


Jules,

As Lex states, it isn't an error to override new. The warning is just a 
caution that improperly overriding it may prevent creations of new 
instances of that class.

A common reason to override new is to run an initialization routine 
after instance creation:
new
     ^ self basicNew initialize

Brian.


On Mar 16, 2004, at 12:16 PM, Lex Spoon wrote:

> Jules Dubois <de6l5rp02 at sneakemail.com> wrote:
>> Lex Spoon wrote:
>>> If you aren't sure, keep in mind that you can always so no and then 
>>> make
>>> a snapshot before trying again.  That way, if anything goes wrong, 
>>> you
>>> can resume from the latest snapshot.
>>
>> Is a snapshot what I get if I select "save as new version" from the 
>> World
>> menu?  That would beat copying the "three files" back and forth 
>> between
>> temporary directories like I did when I was experimenting with 
>> installing
>> browsers (in this case, Refactory and Whisker),
>
> Yes, that and "save as".  Much more convenient.
>
>
>>>>    For example, I tried to create a 'new' method in one of my 
>>>> classes
>>>>    and received a message, "Warning: new is used in the existing 
>>>> class
>>>>    system ...".  Is this just a problem with new?
>>>
>>> You get this warning whenever you define a class method for something
>>> that is already being used in the system.  This is often a mistake, 
>>> but
>>> #new is an exception to this exception.  [...]
>>
>> I don't quite understand this statement.  It's a mistake for me to 
>> use an
>> existing selector for a new purpose or it's a mistake for me to use
>> (override) #new?
>
> It's just a warning.  In the case of #new, the warning is going
> overboard.
>
>
>
>
>> My new theory is, stated in terms of '==',
>>
>>     Squeak can't determine that the receivers of '==' would never be
>>     instances of my class, so it warned me of the existence of these
>>     other receivers when I tried to remove it from my class.
>>
>> Is this closer to reality as defined by Squeak?
>
> Yes, that's pretty good.  In general, the warnings really are just
> warnings, i.e. information that something looks funny.
>
> Honestly, even in a statically typed language, the "errors" are often
> just warnings that the compiler is treating severely enough to reject
> the program.
>
>
> -Lex
>




More information about the Squeak-dev mailing list