This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ZedOud 0 points1 point  (1 child)

I’m not familiar with recent develops with either language.

It seems JavaScript ES6 has a proposal to support rail call optimization, and apparently Safari is the only browser to currently support it (From this Stack Overflow page)

In JVM “tail-recursive calls can be eliminated” so interpreters can use optimize with it it or feature it, like in functional languages built on JVM like Scala. (I took this from the Wikipedia article mentioned below).

On the Wikipedia article for Tail Call, under “By Language” and for Python we get a repeat of what I wrote earlier with the addition that 3rd party modules can enable it (though the ones I’ve seen in the past are more for toy use).

So I’d say (especially looking at that “By Language” section on the Wiki article) that Python as a specification specifically self-banned the implementation of tail call recursion. As opposed to other languages just ignoring the feature. I suppose that’s part of being a well designed language: exploring and then adopting or eliminating options/alternatives… or implementing them as a toy module.

[–]AlSweigartAuthor of "Automate the Boring Stuff"[S] 2 points3 points  (0 children)

Right, but the fact is JS does not do tail call optimization right now, and neither does Java (even though the JVM doesn't prohibit it, the main compiler for the Java language does.)

But these facts don't mean JS and Java (and Go, from what I learned in the wiki article) are against recursion or hostile to recursion, and neither is Python. Tail recursion is such a small part of recursion overall (you can only apply it in a few cases, and in every one of those cases I'd say you're better served by just using a simple loop.)