binary selectors ambiguity and space
Hans-Martin Mosner
hmm at heeg.de
Wed May 17 15:58:27 UTC 2006
Duncan Mak wrote:
> I have always wondered why the standard image doesn't come with a next
> method and an increment method for Integers, where next would answer x
> + 1 and increment would set x to be x + 1.
The first is easy, but in my opinion does not add much value - "aNumber
next" does not help me understand the code better than "aNumber + 1"
does. And of course, it re-uses a selector which is already used in the
stream hierarchy and means something completely different.
The second one is not possible with Smalltalk's semantics. Messages are
sent to objects, not to variables. So whatever message you send to
variable x, it can't cause x to point to another object (with the
exception of #become: but that's a special case). Since numeric objects
are immutable, you need to have the assignment x := x+1 either
implicitly or explicitly somewhere.
I'd like to know concrete use cases where you would prefer an increment
method over an explicit x := x+1. My gut feeling is that such cases
probably could be handled even better by still other constructs (for
example, collections or streams), but of course this can't be said
generally for all cases.
Cheers,
Hans-Martin
More information about the Squeak-dev
mailing list
|