On Aug 26, 2007, at 11:55 PM, Bert Freudenberg wrote:
On Aug 26, 2007, at 11:01 , Fabio Filasieno wrote:
collection := OrderedCollection new.
collection add:1.
evaluates to one. Why ? Why not to collection ?
You do not always add a simple value but the result of an expression. Having the #add: return the argument sometimes lets you avoid introducing a temporary variable. It is more useful this way, and for the cases where you actually want the collection you can use a cascade.
A similar point can be made that setters should return the argument instead of the receiver, although usually in Squeak they do not (Tweak revises that policy).
- Bert -
and Jason's already said that.
ahaaaa ..... I didn't get temp thing right.
( obj send: (... complex stuff....) ) SendToComplexStuff
But I finally got one reason for the cascade!!!!! At last ... (the complex thing helped me on that)
I didn't think of that, as I associated a "void" return with returning self !
For instance in C .. when you don't return anything (void) nothing comes out.
"In Smalltalk instead" I thought
" they do a smart thing. What can you do with void (or Ans) ?Nothing !
So instead of returning a useless void they return self. Smart !
And this worked very well with the functional style that I like.
And I thought that side effects only functions like setters would be done perfectly.
And easy to read to !
But then ...
I thought:
" What ? (((( obj sendA: a) sendB: b) sendC: c) sendD: d ). You must me joking !!!!"
And my yohuoooooo :-D (no need to return self, it's the default ! ) ..... became argh ... here comes parenthesis.
Now if I put into the equation you put a complex expression...
you avoid ...
#Just Returning self
obj property: (complex_stuff)
| property
| ...
and do
#fixing it with ... get some more cases under the belt.
obj property: (complex_stuff)
; .....
Don't know yet if I like it that way ...
But now I see the point; and why somebody might prefer it that way.
I wouldn't be so sure now on cutting the ";" cascade out now.
I would say - but just now - that there is no pipe vs cascade thing.
Thanks for ringing the bell ....
and the pipe might be still better than the parenthesis .... :o)
obj sendAndReturnComplexStuff: (... complex stuff....) | SendToComplexStuff