[Newbies] Re: Two questions about Smalltalk language design
Joseph J Alotta
joseph.alotta at gmail.com
Thu Dec 27 18:04:42 UTC 2012
1. If a message does not return self, then you wouldn't be able to chain messages
together or to cascade messages.
s := Sphere new.
s rotateLeft; rotateRight; spin 60.
would have to be:
s spin 60.
2. If you add an object to a collection, most times you are still concerned with the object, not the collection. I know what you mean that a lot of times you build an object and when it is complete you store it in a collection and move onto something else. But there is no reason adding has to be the final step.
For example, I pour coffee into my cup, (Cup new) add: coffee, then I stir the coffee, (coffee stir) .
> 1) Why do ST methods return "self" if nothing is explicitly returned?
> (he would have expected something like "Unit" in Scala, or "Void" -
> 2) In Collections, why does "add:" return the object being added, and
> not "self"?
More information about the Beginners