Python vs. Ruby
Brian Quinlan
brian at sweetapp.com
Wed Jan 1 17:26:39 EST 2003
John Roth wrote:
> > > It also has a solution to one of the ugliest warts in Python:
> > > the fact that the .append(), .sort() and .reverse() methods
> > > don't return an updated value, so you can't chain them.
> >
> Of course it would be, and I regard the design as a major
> inconsistency in Guido's thinking. Being novice friendly is
> one thing, but penalizing everyone else by crippling chained
> application is quite something else.
It's not just newbie friendly, it's also a semantic aid for experts. If
chaining were typical in Python, then you would have no immediate
indication if a method is returning a new value or (a possibly mutated
version of) itself e.g. from reading this code:
foo.sort()
foo.count('a')
I can intuit that the sort is being done inplace. From this code:
foo.sort().count('a')
I cannot.
Since not using chained methods removes this semantic aid and it only
saves you the cost of typing an identifier, I think that the Python
design is reasonable.
Cheers,
Brian
More information about the Python-list
mailing list