4 ms·
Guido is probably right that tail recursion is unpythonic but he seems oddly proud of this. In defending Python's design decisions, he makes a great case for th
by thefaux 2y ago
Guido is probably right that tail recursion is unpythonic but he seems oddly proud of this. In defending Python's design decisions, he makes a great case for the prosecution.
- kstrauser 2y agoThe first tenet of the Zen of Python: “Beautiful is better than ugly.” Tail recursion is beautiful in the right context. There are plenty of problems where it’s the clear, obvious, elegant way to write an algorithm. Sure, you can rewrite a tail recursive algorithm iteratively. However, not once have I seen a case where the result is easier to read, understand, and reason about than the original version. It’s only unpythonic for the same reason multithreading is: because it’s traditionally sucked in Python. Therefore no one does it. Therefore there’s no perceived demand for it because no one’s doing it. Therefore it’s not changed to make it easier to work worth. Therefore no one does it. Lather, rinse, and repeat. I love Python, but there are a few corner cases like this that drive me to drink.