logoalt Hacker News

layer8today at 11:29 AM0 repliesview on HN

In practice, a heap-based manual stack can be as unsafe with unbounded input as using the native call stack (considering typical OOM behavior). If you have untrusted input, you might want to limit the stack depth in either case. And it’s not difficult to add a recursion counter to recursive calls. So I don’t think it’s an inherently distinguishing feature between the two approaches.

Personally I tend to find the iterative approach easier to follow when no actual stack is needed, i.e. in the tail-call case.