What I don't understand with STCs is, how would I, as a developer, decide when to use them and when not?<p>As program correctness is concerned, tail calls and recursive calls should behave exactly the same (except stack use), so going by correctness alone, either the choice doesn't matter at all or tail calls are preferable. So the logical thing to do would be to always use tail calls.<p>The post goes on to list a number of disadvantages, but those seem to be either debugging concerns or platform-specific implementation concerns.<p>The former doesn't seem to be something that should be solved in the code - the document itself lists a number of solutions. The latter is not something that I as developer could judge as I likely don't have knowledge about the specific implementation of the platform the code is running on (if I know the platform in advance at all)<p>So it seems to me, STC shifts the problem of deciding to the developer even though the developer has no good tools to actually solve it.
Until ES6 which introduces Tail Call Optimization, you can use trampolines.<p>Small summary code:
<a href="http://paste.ubuntu.com/24568118/" rel="nofollow">http://paste.ubuntu.com/24568118/</a>
What's the best way to benchmark perf optimizations in JavaScript. I see lot of articles like this with no time and memory usage stats.
I would like to hear an answer from someone who has experience using gdb or visual studio while studying performance. Whenever I use the chrome debugger to time anything involving async calls and recursion I have this uncomfortable feeling I am not getting it right. With gdb or visual studio C/C# I always feel like I know what is going on.
JavaScript TCO can't be feature detected so how do you know when tail calls are safe to use in front end or library code that can run on a variety of clients?