I'm not the creator of a little trick, but it seems like this is the best you can do.
For example, if you do:
var := myInstance myMethod.
then the question arises: what do you want var to become? One option would be nil . But this is a bit confusing because you are working with certain objects, and nil is actually undefined. That way, you can relate to it when you assign myInstance var and just call myMethod along the way. Also, this can probably be considered a reduction for
var := myInstance myMethod; yourself.
If you look from the inside, then of all the data available to the object itself, the most suitable thing is probably also self . Once again, nil can be returned, but I already said my opinion about this before.
In Smalltalk there is no such thing as a void method that returns nothing, and type checking does not exist. Therefore, the method just needs to return something. He, like the object, says:
I can return myself for any call to the default method, because I always find out about myself, and you can override this behavior if you want to return something else to me.
Personally, I think that returning nil can also be good, and Objective-C applications use nil things very often, but Smalltalk is created this way, and I think this is a good solution.
Uko
source share