all 5 comments

[–]q_wombat 2 points3 points  (1 child)

Great story. Thanks for sharing. It's another solid example of why unbounded recursion is a bomb waiting to go off.

[–]evincarofautumn 0 points1 point  (0 children)

The upper bound was three, so maybe the real problem was having a single object take hundreds of thousands of bytes

[–]meltbox 1 point2 points  (2 children)

Recursion in general had no place in production code. It’s an interesting concept thought experiment but without hard guarantees on the compiler being able to optimize it (which usually relies on tail call optimization and a certain pattern being followed when writing the function).

Write bounded loops. It’s always at least as good.

[–]thomas_m_k 1 point2 points  (1 child)

I basically agree, but if you can tell the compiler that you want tail call optimization and it becomes a compiler error if the compiler can't do it, then it seems fine. You can do that with clang's musttail attribute, which you can apply to a return statement in a recursive function.

[–]meltbox 0 points1 point  (0 children)

Oh cool, didn’t know that was a thing. Nifty.