r/Python • • Nov 11 '08

Why the hatred for functional programming?

0 Upvotes

86 comments sorted by

View all comments

Show parent comments

6

u/llimllib Nov 11 '08 edited Nov 11 '08

Besides lack of support for tail calls, which is the only example you give, what makes you think that python doesn't support functional programming? What proposals do you refer to that have been shot down?

My POV: Python spports FP just fine as long as it doesn't conflict with python itself. Remember that Python has:

  • list comprehensions

  • generators

  • coroutines

  • filter map and reduce built-in

  • real first-class functions with closures (albeit those can be a bit quirky)

All of those things point to no fundamental language bias against FP.

2

u/Wiseman1024 Nov 11 '08

Besides tail call elimination, which could be added but and it's not being rejected because it can't be done, but because it's deliberately unwanted, I have:

  • Guido's stubborn quest to make lambda useless by not accepting statements inside it, or by not making statements expressions. He even wanted to remove it at one point, but he saw it was pressing too hard.

  • The closures are pretty real, but the way scopes are handled is inconvenient. It could have been fixed in so many numerous ways so long ago, but it was always an nth-priority. The chosen solution, nonlocal, is acceptable but suboptimal. Expanding lambda into a def with better semantics would have been much, much better, and even more backwards-compatible, since it wouldn't require the introduction of a new keyword.

  • The "flat is better than nested" philosophy is keeping the language from becoming more expressive. In particular, it still has statements. They need to die. I've been talking somewhere else in Reddit about how we could have Python be fully backwards-compatible while turning its current statements (a design wart from the age of Fortran) into expressions. There are countless advantages to that, which is basically lifting a limitation, but I've seen the community even wants an arbitrary limitation to stay just so that you cannot write more flexible code.

  • filter, map and reduce? You're pointing out a weak spot, not a strong one. First of all, Guido actively discourages their use in most cases, and he's moving reduce out of builtins (he also expressed his dislike of it many times).

  • More importantly, Python ships with an extensive standard library to handle text in many ways, lots of class utilities, lots of pretty much everything, and almost no FP-related utilities in comparison. The FP utilities have been neglected since ever. Where are promises, futures, foldr, foreach/repeat/other functional loop constructs, scanl/r, flip, prog1, progn, conses, memoizators...?

2

u/[deleted] Nov 12 '08

What you're saying is reasonable, but it sounds like Python isn't your cup of tea, so why don't you use a different language?

I'm not trying to pick a fight, it just sounds like Python pisses you off.

1

u/Wiseman1024 Nov 12 '08

The reason why this anti-FP attitude (or, at least, FP neglect) pisses me off and I'm passionate about it is that I care for Python, because I otherwise love it. I'd like to settle with Python as my main language for several years, and I'm just complaining about what's keeping me from doing this.

It's just because Python is so close to my ideal language that I bother to bitch about what I don't like from it; I don't bother with, say, Perl or PHP because they are pretty far from what I want.