r/Python • • Nov 11 '08

Why the hatred for functional programming?

0 Upvotes

86 comments sorted by

View all comments

Show parent comments

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 :)