r/Python • • Sep 29 '16

O'Reilly offers "Functional Programming in Python" by David Mertz as free eBook.

http://www.oreilly.com/programming/free/functional-programming-python.csp?cmp=em-prog-free-na-lgen_safari_20160929
847 Upvotes

69 comments sorted by

View all comments

16

u/DonaldPShimoda Sep 29 '16

I'm excited to check out this book when I've got a chance!

That said, here's a related SO post about "Why isn't Python very good for functional programming?"

18

u/ubernostrum yes, you can have a pony Sep 30 '16

It's worth noting that most "Python is bad for FP" views -- including the one you linked -- really boil down not to "Python is bad at FP", but rather "Python allows this to coexist with other paradigms of programming". Most of the things people then say they'd want to make Python "better" at FP ultimately are "turn Python into a single-paradigm FP language", not "keep Python multi-paradigm, but improve the FP constructs".

4

u/wting Sep 30 '16

Most of the things people then say they'd want to make Python "better" at FP ultimately are "turn Python into a single-paradigm FP language", not "keep Python multi-paradigm, but improve the FP constructs".

I think this is a really valuable insight. The reality is when designing a language you can encourage pardigms by making it easier / more difficult. At the end of the day, GvR doesn't like FP and he will not make it easier to do in Python.

In fact, lambdas and functools only made it into Python because of an early contributor during Python 1.x or 2.2 days and people used it. Now GvR's stuck with it for backwards compatibility purposes.

I code FP-style Python when it's appropriate, but I wish people wouldn't kid themselves and pretend Python's a first-class functional language (or will ever be).

4

u/ubernostrum yes, you can have a pony Sep 30 '16

Some of the suggestions in the post aren't bad, but would change the character of the language.

Others -- like automatic currying -- probably can't be integrated into Python in any useful way (automatic currying and variadic functions don't play super nice together, and if forced to choose one or the other I'd keep variadic functions easy and make currying something you have to do explicitly).

7

u/DavidMertz Sep 30 '16

I quite like http://toolz.readthedocs.io/en/latest/curry.html. I didn't know about this library when I wrote the book, but it is very good.

1

u/hanpari Sep 30 '16

And what about pyrsistent? I believe toolz and pyrsistent are quite fundamental for FP in Python :) I thought both of them were included in your book.

Maybe I would add attrs https://attrs.readthedocs.io/en/stable/

Even it is not quite FP but can help o reduce codebase significantly.

BTW, your book is great, thank you.