On Sun, Jan 19, 2020 at 2:57 PM Tim Peters <tim.pet...@gmail.com> wrote:
> [David Mertz <me...@gnosis.cx>] > > What we get instead is a clear divide between mutating methods > > on collections that (almost) always return None, and functions > > like sorted() and reversed() that return copies of the underlying > > collection/iterable. Of course, there are many methods that don't > > have functions matching them. Python could have been designed > > differently, but using the consistency it follows is best. > > For a bit of history that I may have made up (heh - memory fades over > time!), as I recall, the very first Python pre-releases echoed to > stdout every non-None statement result. So, e.g., > > for i in range(5): > i > > displayed the same as the current > > for i in range(5): > print(i) > > But one prolific early user loved chaining mutating method calls, each > returning `self`, and so their output was littered with crap they > didn't want to see. They didn't want to prefix every computational > statement with, e.g., "ignore = ", so Guido stopped the magical > output. > I generally like the result. I used some fluent interfaces long before the term was coined in 2005. In fact, several years before I used Python first in 1998. And I still sometimes really enjoy doing those Pandas-style long method chained operations. In my personal experience, I think I first used the style in some XBase-family languages that added OOP extensions (I really miss those, actually; Clipper was a really elegant language that not so many folks grew up with as various others). In Pandas it makes some sense, and is even the mostly preferred style to use. So much so there that there is talk of deprecating the `inplace=True` option that exists on most DataFrame methods. But Pandas very much eschews lops and focuses on vectorized operations. For those, I think the case for fluent interface is more compelling. In contrast, in pure Python, most of that you do is in loops over the elements of collections. In that case is does a good job of drawing your eye to the fact that a method is called but not assigned to anything. When I see `mylist.append(foo)` on a line by itself, the absence of an assigned variable drives home "this is basically a statement, called for side-effects" (yes, I know in the syntax it is an expression not a statement; but my looser cognitive model works that way). If all those mutating methods returned something meaningful, it would seem less obvious whether I was looking for the modified version of the collection or the returned thing... and whether those two would be identical to each other or not. With .append() we use it so much that it would be very familiar. But other methods of collections are "once a month" or "once a year" friends, not "ten times a day" ones... and one might forget. Yours, David... -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KDE2C7OAMZYUGYIHFLCOSR4XEYK65TZK/ Code of Conduct: http://python.org/psf/codeofconduct/