This is an old debate. On the one hand with tail calls you can write recursive code and find that it runs fast without excessive memory. On the other hand when things blow up, it is really nice to have a stack backtrace to help debug why it blew up. But a stack backtrace can't include stack frames that were optimized away. Which makes it far harder to figure out why this call on this object turned into that call on t…
> On the other hand when things blow up, it is really nice to have a stack backtrace to help debug why it blew up. But a stack backtrace can't include stack frames that were optimized away. Which makes it far harder to figure out why this call on this object turned into that call on that object. Is that really a concern? If you're writing a loop, do you expect your tools to show you a trace of every iteration in the…
Why Object-Oriented Languages Need Tail Calls (2011)
11–20 of 72 posts
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#12They don't need tail calls, unless you're planning on doing idiomatic functional programming in an OO language, which, Why??
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#13Earlier quoted context omitted.
> On the other hand when things blow up, it is really nice to have a stack backtrace to help debug why it blew up. But a stack backtrace can't include stack frames that were optimized away. Which makes it far harder to figure out why this call on this object turned into that call on that object. Is that really a concern? If you're writing a loop, do you expect your tools to show you a trace of every iteration in the…
Tail recursion optimisation gets rid of all tail calls in functions, not just those that might lead to loops - you cannot in general detect those calls that might be loops. This can put a lot of holes in your stack trace.
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#14Earlier quoted context omitted.
Tail recursion optimisation gets rid of all tail calls in functions, not just those that might lead to loops - you cannot in general detect those calls that might be loops. This can put a lot of holes in your stack trace.
It's an optimisation. It can be turned off when debugging with stack traces. If you need stack traces in production code, you have too many partial functions.
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#15If you had to explicitly request it, say by doing `tailcall f()` instead of just `f()`, that would mostly fix these problems. Control flow will be a lot less confusing since it'll be explicit in the code (but you still lose information from the optimized-out stack frames, no way around that) and you'll get an explicit error if someone tries to add something that can no longer be tail call optimized, like `tailcall f() + 1`.
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#16Why don't languages give tail calls their own syntax rather than making it an optimization? It seems like a lot of the arguments against tail calls boil down either 1) it's confusing when things go wrong and you weren't expecting stack frames to be optimized out or 2) it's hard to safely write tail-recursive code because a small change to the code or, worse, the compiler settings can make it stop being tail-recursive…
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#17Earlier quoted context omitted.
It's an optimisation. It can be turned off when debugging with stack traces. If you need stack traces in production code, you have too many partial functions.
But you can't ever turn it off if you rely on it for loops, which defeats the whole point.
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#18Why don't languages give tail calls their own syntax rather than making it an optimization? It seems like a lot of the arguments against tail calls boil down either 1) it's confusing when things go wrong and you weren't expecting stack frames to be optimized out or 2) it's hard to safely write tail-recursive code because a small change to the code or, worse, the compiler settings can make it stop being tail-recursive…
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#19This is an old debate. On the one hand with tail calls you can write recursive code and find that it runs fast without excessive memory. On the other hand when things blow up, it is really nice to have a stack backtrace to help debug why it blew up. But a stack backtrace can't include stack frames that were optimized away. Which makes it far harder to figure out why this call on this object turned into that call on t…
I wouldn't expect the same from an OO language, but I'm not sure that it's impossible either.
Re: Why Object-Oriented Languages Need Tail Calls (2011)
#20Why don't languages give tail calls their own syntax rather than making it an optimization? It seems like a lot of the arguments against tail calls boil down either 1) it's confusing when things go wrong and you weren't expecting stack frames to be optimized out or 2) it's hard to safely write tail-recursive code because a small change to the code or, worse, the compiler settings can make it stop being tail-recursive…