News for hackers. Stuff that matters.
Re:How recursion got into programming: a comedy of errors by chriswarbo on Wednesday July 23, 2014 @10:21AM (#8074482)
Replacing recursion with a loop can easily use extra memory. The usual approach is to implement a stack using a local variable: each iteration pops the head and processes it; rather than recursing, we push a new item and let the next iteration process it for us.

If the algorithm is tail-recursive, this will use constant stack space and memory, just like tail-call optimisation. If the algorithm's not tail-recursive, it will use constant stack space but large (potentially exponential) amounts of memory.

There's no way around this. The only solution is to come up with a different algorithm (eg. using an accumulator).

Re:How recursion got into programming: a comedy of errors by to3m on Wednesday July 23, 2014 @04:37PM (#8076821)
You're usually better off with manual recursion, if you're concerned about running out of space, for the simple reason that it's far easier in practice to back out of an out-of-memory situation than from a stack overflow.
Re:How recursion got into programming: a comedy of errors by Retric on Wednesday July 23, 2014 @01:03PM (#8075470)
Optimal loops don't use more memory than recursion and generally significantly less. Though if you can find an counter example in a common programming language I would love to see it.

However, we are talking about the automotive and aerospace industry so recursion overhead is often a deal breaker even if there are no other issues.