Category Image Playing with self in Smalltalk 


 


I was reminded of an old trick recently and decided to write about it here. This little excursion came about because someone showed me something they could do in Smalltalk the other day that I had never tried before.

They wrote a method #self.

For example, on a class they wrote a class method #self that looked like this:

self
^ 42

While this was amusing it reminded me of a trick I used to teach people back in the days when I used to conduct Smalltalk troubleshooting workshops for Digitalk's customers.

Try to lookup senders of "self" in your Smalltalk image. After the initial laughter, you begin to realize something. There shouldn't be any. With a few well understood exception cases, you should never find any. If you found a sender of "self" you generally had a missing "." somewhere in your code.

Now I remember that Smalltalk/V had something like 4 places where there were in fact senders of "self". They were all references to "self" as a symbol in a collection. I just tried this on my Squeak image and found 13, all symbols.
 

Posted: Thursday - October 27, 2005 at 03:35 AM           |


©