Brian Candler wrote:
> On Wed, Sep 03, 2003 at 04:16:19AM +0900, Hal Fulton wrote:
> 
>>I've just realized that in the back of my mind, I prefer passing
>>the "little object" into the "big object" rather than vice versa.
>>Hmm. A psychological aspect there.
>>
>>Much of what Ruby already does bears this out, I think.
>>
>>    array << item       # not item << array
>>    stack.push(item)    # not item.push(stack)
>>    queue.add(item)     # not item.add(queue)
>>
>>Junk-food for thought...
> 
> 
> But perhaps more importantly: we expect the receiver of a message to modify
> its state, not the sender.
> 
>      item.push(stack)
> 
> would be sending a message to the item to push itself onto a particular
> stack; the item would be unchanged by the action, but the stack would be
> changed. This is getting very close to the procedural
> 
>      push(stack,item)
> 
> since the 'push' method would need to know about the internal instance
> variables and organisation of a stack in order to be able to update it. And
> then that logic would have to be put into every possible type of 'item' that
> you wanted to be able to push onto a stack !
> 
> The Ruby Way is that the stack itself knows how to push/pop items, and
> doesn't care what kind of object it is given to push (all it's doing is
> copying a reference to it, after all). That makes a great deal of sense.
> 
> Not that this necessarily helps the paper.draw(object,pen) discussion, but
> the particular examples you gave do seem to have a natural sender/receiver
> divide.

Thank you, that is perceptive.

Actually, this does also apply to the real-world examples
I mentioned.

     text.annotate(image)   # counter-intuitive to me: in both cases,
     polygon.draw(window)   # parameter (not receiver) changes state

Hal