top | item 33423049

(no title)

zaccusl | 3 years ago

The only time I've ever ran into a stack limitation was real-time embedded systems with a tiny stack.

For modern computers/tablets I have never experienced an issue. Granted, what really matters is your data/recursion level, but even hundreds of recursive calls are not a problem for most applications.

Recursive solutions are usually so much easier to understand than stack/array based looping solutions that they are my go to for things like tree traversals or searching.

discuss

order

ak217|3 years ago

> for most applications

A very subjective statement. Yes, your data matters. Also, the scale and security model/trust boundary of your application matters.

Some actual problems with recursion based algorithms:

* They will break unexpectedly as you scale them up.

* They are not memory efficient, so you won't be able to process much in parallel if your data is non-trivial.

* They can make your service trivially DoSable, so now you have to worry about either sanitizing your input or monitoring your stack instead of just timeouts/rate limits.

I've lost track of the number of times I've had to tweak JVM settings, write up security issues, or just straight up tell people things won't work because an academic researcher decided to implement an algorithm with recursion, and then engineers were asked to productize it.