r/Python • • Nov 11 '08

Why the hatred for functional programming?

0 Upvotes

86 comments sorted by

View all comments

5

u/Wiseman1024 Nov 11 '08 edited Nov 11 '08

Okay, I don't think I need to tell why I'm asking this. While Python supports functional programming to a reasonable extent, there's a widespread stubborn hatred of functional programming and anything related to it in the Python community (probably starting with the BDFL), and any proposals for extending Python into something more useful for functional programming (without taking out any of the other ways to use Python, of course, that's the good thing about multi-paradigm languages) is received with ruthless hostility and perceived as an attack against Python.

The Python community is generally a good one (especially compared to others), yet this generalized hatred for functional programming and anything related to it seriously turns me off. While Python is currently my overall favourite programming language (considering the quality of the standard and non-standard libraries, support, and features), I'm currently considering putting my effort and time investments somewhere less hostile to functional programming.

Hostility to functional programming is a form of hostility to abstraction, theoretical correctness and cleanliness. I hope I'm wrong, but this seems like pulling the PHP way. Consistently meeting proposals such as tail call elimination with nothing short of "that's liek difficult to understand d00d ha ha no freaking way" doesn't say much about the health of this community; in fact it looks like something straight out of the average PHP documentation comment.

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.

3

u/llimllib Nov 12 '08 edited Nov 12 '08
  • Guido prefers named functions to unnamed ones; it's his language, how does that affect the functionality of the language?

  • The scope handling is what I was referring to as a bit quirky. I can see this as a beef with the language, and might even agree somewhat, but I don't see it in the light of opposition to FP that you do.

  • Again, I cautiously agree while seeing your point as largely orthogonal to your original hostile-to-FP complaint.

  • Who cares if they're in builtins or functools? Or if Guido prefers spelling filter(lambda x,y: something(x,y), collection) as [something(x,y) for x,y in collection]?

  • It definitely doesn't ship with an FP toolkit, and the stdlib doesn't return self on some things that are truly maddening. However, I see that as being because Python is not a primarily functional language, and so the builtins need can reflect that.

However, the language also doesn't do anything to prevent you from adding those. If anything, I think the language should be characterized as cautiously tolerant of FP style, with one big exception, tail calls.

(Furthermore, you're making fine rational arguments (in our thread at the least) and people shouldn't be downvoting you. Raise your level, redditors.)

2

u/Wiseman1024 Nov 12 '08

Guido prefers named functions to unnamed ones; it's his language, how does that affect the functionality of the language?

It doesn't affect the functionality outside namespace pollution, but it affects readability. Wasn't readability a goal of Python?

Who cares if they're in builtins or functools?

Not too important (every of my modules does import * from functools on top), but it shows the focus. You asked if there's a fundamental bias against FP and I was replying to that.

However, I see that as being because Python is not a primarily functional language, and so the builtins need can reflect that.

Python is not primarily a language for writing HTTP servers, yet it ships with one in the standard library. Even if it's not the main focus, FP could be given some attention.

(Furthermore, you're making fine rational arguments (in our thread at the least) and people shouldn't be downvoting you. Raise your level, redditors.)

My grandparent post was seen as criticism on Python, so I guess the fanboys will downvote. Since there are more fanboys than people willing to engage in rational discussion, the total score is going to be negative. Same as for the whole Reddit post.

1

u/khammack Nov 12 '08

Guido's stubborn quest to make lambda useless by not accepting statements inside it,

Isn't the whole concept of 'statements' counter to functional programming?

The "flat is better than nested" philosophy is keeping the language from becoming more expressive. In particular, it still has statements.

So you want lambda to accept statements (which would make it less functional), then you want statements eliminated from python.

The closures are pretty real, but the way scopes are handled is inconvenient.

I can hardly view this as "hatred" for functional programming.

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...

What stops an enterprising team of functional programmers from creating an open-source functional library ala "numpy"?

1

u/Wiseman1024 Nov 12 '08

So you want lambda to accept statements (which would make it less functional), then you want statements eliminated from python.

I want either. Of course, it'd be best if we had no stinking statements, but either would serve to make lambda work better.

What stops an enterprising team of functional programmers from creating an open-source functional library ala "numpy"?

Nothing, I have mine too (and will publish it once I deem it properly tested). I was replying to llimllib's post on bias against FP.