On Sat, Nov 27, 2021 at 10:52 PM Stephen J. Turnbull
<stephenjturnb...@gmail.com> wrote:
>
> Raimi bin Karim writes:
>
>  > 📌Proposed implementation
>  > Earlier in the thread, Chris proposed a custom class for this kind
>  > of pipeline.
>  > But what if we exposed this as a Python module in the standard library,
>  > parking it under the group of functional programming modules?
>
> The thing is, the reason such a module is needed at all is that Guido
> decided ages ago that mutating methods should return None, and in
> particular they don't return self.

Pipeline programming is usually about constructing new objects, not
mutating existing ones, whereas "fluent programming" can also mean
method chaining (one of the other Steves explained it better than I
can, search up in the thread for D'Aprano).

The policy of not returning self is, from my understanding, to clarify
which methods return a new thing and which mutate the existing one. It
makes this sort of distinction very obvious:

# Works correctly
by_name = sorted(people, key=lambda p: p.name)

# Clearly gives a borked result
by_name = people.sort(key=lambda p: p.name)

If list.sort() returned self after mutation, the second one would
appear to work, but would leave the original list in a different
order.

> As for "only way," I think _Dataflow Programming in Python_ and
> _Fluent Programming in Python_ are great titles for books.  Maybe you
> could write one of those?  I'm half-joking, of course, because writing
> a book is not something anyone should impose on somebody else.  But
> you do have the passion part down already. :-)

I'm sure they already exist! Actually, if you keep an eye on Humble
Bundle, they often have (electronic editions of) books on sale. In
fact, there's a Python bundle right now, though none of the books have
those exact titles.

> (And don't forget to
> have a cute animal for the cover if you go O'Reilly for the
> publisher!)

I've never understood the correlation of animal to title. For
instance, "Using Asyncio in Python" has a frog, "Flask Web
Development" has a dog, and "Think Python" has a bird. But hey,
"Introducing Python" and "High Performance Python" both have snakes on
the covers, so that's a plus.

Maybe it's to remind us not to judge a book by its cover or something :)

ChrisA
_______________________________________________
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/EZRYOGI5PPA6KSORMHRA5ICXOTSJUQFB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to