On 11/12/11 03:23, Lie Ryan wrote:

If returning 'self' is the default expected behavior, it would cause
inconsistencies with respect to immutable types. For example, `5
.__add__(2)`, one could expect it to return 5 instead of 7.

That's not a case where default behaviour would be invoked.
I'm talking about where None is currently returned. Returning None in the above case would make arithmetic impossible.

In "modifying" immutables you have to return the modified value, that wouldn't change. And the same applies in Smalltalk, you only return self as a default value in those situations where there is no specific return value required (as Steve put it, for a "procedure like" function).

It just makes those procedure like functions more usable IMHO.

While I liked the attraction of "fluent interface" of being able to
easily chain function calls, it is inherently more inconsistent than
what Python are doing.

I disagree.

However there are so many Smalltalk like features in Python that I'm sure Guido was well aware of returning self as an option and he obviously deliberately chose not to. So he presumably felt the gains were outweighed by the negatives.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to