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.

4

u/ubernostrum yes, you can have a pony Nov 11 '08

Well, mostly there seems to be resistance to turning Python into Scheme, because, well, if you like Scheme it's already there for you to use (I'd make a joke here about how a future revision of Scheme should turn non-tail-recursive functions into a compiler error, but I'm afraid somebody would actually think that's a good idea). Oh, and for the record: I'm against tail elimination in Python simply because it seems inevitably to lead to people writing obfuscated, hard-to-read code simply for the sake of having a tail-recursive function, and Python is, well, not about that: it's about clear, readable code.

But as others have pointed out, one of the biggest problems, to me as a Python programmer, is the zeal with which FP folks approach this; it's not a case of "we want the ability to do more FP stuff in Python", it's "FP should be the one and only way in which programmers are allowed to write code". You yourself are leaning that way with your straw-man "hostility to abstraction" swipe (hint: OOP is also abstraction. It's different abstraction than FP, but it's abstraction nonetheless).

Meanwhile I'm quite happy to take advantage of closures, comprehensions, coroutines, function composition and all the other things Python lets me do, without thinking that has to be the only way I think about or write code. So maybe the problem is in yourself and not in Python :)

3

u/arnar Nov 12 '08

I'm against tail elimination in Python simply because it seems inevitably to lead to people writing obfuscated, hard-to-read code simply for the sake of having a tail-recursive function, and Python is, well, not about that: it's about clear, readable code.

That's a pretty weak reason. You can (ab)use many of Python's features to make extremely obfuscated code - such as decorators, metaclasses, context managers etc. etc.

The best reason (although I don't think it is a good one) against tail-call-elimination is confusing stack traces in case of exceptions.

Tail call elimination also actually allows you to write clearer code while still being efficient.

1

u/Wiseman1024 Nov 12 '08 edited Nov 12 '08

Exactly. And stack traces can be fixed as well by just keeping the first and the last call in the stack (or just the last), along with the number of omitted calls. It'd require an additional property in stack frames: the number of tail call to the same function it is. This would still mess with cooperative recursion, but that's a lesser issue.

1

u/arnar Nov 12 '08

Besides, it wouldn't be to hard to supply a debug parameter that turns off tail call elimination. If you are debugging an exception where the stack indicates eliminated frames - you would just turn it on and see the full exception.

Of course, then your stack might blow long before you get your exception though :)