3 ms·
The 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
by kstrauser 2y ago
The 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.