Adding and removing methods

Lex Spoon lex at cc.gatech.edu
Tue Mar 16 04:56:12 UTC 2004


Jules Dubois <de6l5rp02 at sneakemail.com> wrote:
> I'm writing my first Smalltalk code in Squeak and I've got two questions.

In both cases they are just warnings.  If the warning seems silly, then
you can tell the system to do it anyway.

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.


> 
> 1) If I create a method in a class, does it need to match the other uses
>    of the selector in other classes?
> 
>    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.  Just tell it to procede.

An example I used to screw up all the time, before this preference came
around, was to make a method called #name.    Doh, now the system cannot
ask a class for it's name without calling my code!  :)  Unfortunately,
there is still no warning for accessing a variable called name -- I
still do that every few months or so with bizarre results.



> 2) If I create a method in a class using an existing selector, how do I
>    remove the method from the class?
> 
>    For example, I created an '==' method in a class but I want to get rid
>    of it.  When I try to do this, I get a message saying there are
>    thousands of senders of this message.  It looks to me like Squeak wants
>    to remove the selector from the system and not simply remove the method
>    from the class.

No, it is talking about removing just the method.  Just click "remove
it" if you want that method to go away.  (And incidentally, you probably
want to implement =, not ==.  = means the normal "generally the same
thing", while == means "exactly the same object")  


-Lex



More information about the Squeak-dev mailing list