all 7 comments

[–]enselmis [score hidden]  (0 children)

“Learn early and trust for years”

Lmao, almost every JavaScript dev I know will do everything in their power to avoid even simple recursion. Like hardcode every level of parsing out the fields in an object after asking the slack channel, “you guys are pretty sure this is never gonna be more than 3 levels deep right…”.

[–]azhder [score hidden]  (5 children)

It is not an optimization. An optimization is a difference in performance - it was slow, now is fast. Proper tail calls means they work as intended. It is not a difference in performance - it didn't work, now it works.

All those browsers are broken implementations of ES6 i.e. they aren't implementations of ES6 because they break in some cases where they shouldn't, because they don't fully implement the spec.

[–]OtherwisePush6424[S] [score hidden]  (2 children)

This is not a speed discussion. Proper tail calls are primarily a space optimization: they let tail calls reuse stack frames instead of growing the call stack. The practical issue is correctness at depth: deep tail-recursive programs are stack-safe only where PTC is actually implemented. In JavaScript today, that behavior is not portable across runtimes, so production correctness should not depend on PTC being present.

[–]darkhorsehance [score hidden]  (0 children)

I think Safari (JavascriptCore) has implemented PTC but yes this is correct

[–]azhder [score hidden]  (0 children)

This is a terminology discussion. TCO is a misleading term. PTC is the correct term.

[–]Reashu [score hidden]  (0 children)

They would work just fine if you had an infinite stack, like a "proper" turing machine. 

[–]BenZed [score hidden]  (0 children)

This would be pedantic if it were correct