News for hackers. Stuff that matters.
Re:How recursion got into programming: a comedy of errors by liotier on Wednesday July 23, 2014 @09:41AM (#8074282)
> tail call optimization is basically the compiler doing that conversion for you which removes the risks.

Then can one argue that loops vs. recursion is mostly a matter of style and loops just as good as recursion since the compiler will optimize them that way anyway ?

Re:How recursion got into programming: a comedy of errors by axman6 on Wednesday July 23, 2014 @09:39PM (#8077847)
Not all recursive functions can be rewritten to be non-recursive. The Ackerman function is one such example. It's clearly tail recursive, but not only tail recursive so it must use some kind of stack or tree or something which isn;t linear like a loop. there's some explanation on the Computerphile youtube channel discussing it: https://www.youtube.com/watch?v=Mv9NEXX1VHc
Re:How recursion got into programming: a comedy of errors by dspillett on Wednesday July 23, 2014 @09:54AM (#8074349)
Yes, but only in the cases where the tail recursion optimisation is applicable.

Recursive constructs are can be not tail recursive (and usually are with new starter developers) and many languages ignore it anyway (meaning even code that can be unpacked from function calls into a loop are not so the stack is still used).

Re:How recursion got into programming: a comedy of errors by rubiquity on Wednesday July 23, 2014 @09:55AM (#8074350)
Yes, but humans mess up loops far more frequently than compilers do. If we follow your argument recursively, we would all end up writing assembly language again, wouldn't we? :)
Re:How recursion got into programming: a comedy of errors by coldtea on Wednesday July 23, 2014 @10:42AM (#8074602)
Is that meant as an argument against loops and pro recursion?

Because humans also screw recursion all the time.

Re:How recursion got into programming: a comedy of errors by rubiquity on Wednesday July 23, 2014 @11:00AM (#8074689)
I guess. But if I make the mistake of infinitely recursing I find out the next time I run my program. If I'm writing my own loops and make an off by one error it could go uncaught potentially forever.
Re:How recursion got into programming: a comedy of errors by pekk on Wednesday July 23, 2014 @12:24PM (#8075193)
You don't necessarily find out the next time you run your program. A stack overflow can go uncaught potentially forever.
Re:How recursion got into programming: a comedy of errors by PaulHoule on Wednesday July 23, 2014 @12:48PM (#8075354)
One of my favorite PHP gotchas is to accidentally write a function that calls itself infinitely, and then have the interpreter die without a warning message.
Re:How recursion got into programming: a comedy of errors by mtdewcmu on Thursday July 24, 2014 @12:09AM (#8078178)
If a program is only doing a simple calculation and it's still running an hour later, you should probably suspect an infinite loop and not wait for it to stop.
Re:How recursion got into programming: a comedy of errors by Rusky on Wednesday July 23, 2014 @02:13PM (#8075937)
So use iterators? Sometimes loops are just the clearer way to express something.