3 ms·
> it's easier to take advantage of the fact that the programming language is already providing us a call stack Exactly, I think this point is often overlooked,
by Terr_ 9y ago
> it's easier to take advantage of the fact that the programming language is already providing us a call stack
Exactly, I think this point is often overlooked, because folks get stuck thinking about the syntax of what they're writing rather than how it works under the hood.
- SOLAR_FIELDS 9y agoIt's nice unless your language has a limiting call stack. JVM languages are notorious for this. You can increase the size of course, if you have the right amount of machinery. Else it's time to explore tail call recursion and other "anti-unrolling" strategies.
- joshlemer 9y agoSome languages on the jvm (namely scala) do have tail call recursion, meaning that in many cases recursion can use constant stack space
- chii 9y agoI thought you had to manually mark the method (and/or the recur site) for scala to do tail call optimisations.
- chii 9y agoMost languages don't limit stack size at the language level, but at the impl. This is true for Java and for C++.
- Terr_ 9y agoI think a useful litmus test is to consider the worst-case depth of whatever you're building. I often feel safer writing my own userland stack, even for stuff like DFS in an interview. You can't always know how much of the implementation stack will already be used by whatever calls your code, after all. It's a weird kind of "shared resource".