Hacker News new | ask | show | jobs
by asciimov 1460 days ago
After thinking about this for a bit, the decision to avoid including this functionality is probably for the best.

Even though I would love for this feature to exist, I can see people unintentionally shooting themselves in the foot and not understanding why.

Often when you run up against call stack limitations, you actually need to reconsider the algorithm being used.

Trampolines can be used to bypass the call stack limitation. As an advanced technique, the majority of people having issues with a call stack problem will reconsider their solution before thinking about jumping on the trampoline.

1 comments

How can this be bad or a footgun?

If the algorithm can be PTC optimized, then it is and everything works as efficiently as possible.

If not, then it blows the stack either way.

Finally, a trampoline is objectively worse. The programmer has to have an even bigger understanding of tail calls. Trampolines involving complex patterns are MUCH more difficult to follow. The trampoline is implemented in JS rather than C++. The trampoline will require additional function overhead that cannot really be eliminated. The Trampoline isn't anywhere near as optimizable by the JIT either.

Trampolines are all downsides in comparison with proper tail calls.

> How can this be bad or a footgun?

You are coming from the side of someone who already has a a well planned algorithm that doesn't get stuck in infinite looping or end up diving too deep.

My concern was for those without a well planned algorithm, who don't see that it can get stuck in a loop or dives too deep too quickly. In these situations blowing your stack is a good indication you have a problem.

This is just my bias of dealing with programmers who don't do well with recursion or love to introduce function call hell.

52% of mobile traffic runs on iOS which implements PTC, but the world doesn't end. 1 in 9 desktops use Safari which also implements PTC without issue.

They've been using PTC since 2016 as I recall and all the complaints that the world would break simply haven't happened.