News for hackers. Stuff that matters.
Re:Thinking About Recursion by codr7 on Sunday October 11, 2020 @10:04AM (#24745850)
The tail-recursive version of fibonacci runs just as fast as the iterative in languages with optimized tail calls.

Tree- and graph traversal is often easier to reason about using recursion from my experience.

Worst case, you can get the same effect by pushing recursive calls on a stack/queue that's consumed iteratively.

Re:Thinking About Recursion by glandium on Sunday October 11, 2020 @06:54PM (#24749822)
Code generated with tail-call optimization is, in fact, literally a loop.
Re:Thinking About Recursion by tgv on Sunday October 11, 2020 @12:59PM (#24747210)
The recursive version of Fibonacci is generally not tail recursive, but f(n) = f(n - 1) + f(n - 2).
Re:Thinking About Recursion by codr7 on Sunday October 11, 2020 @06:36PM (#24749714)
It's easy enough to convert by adding arguments for the two variables used in the iterative version:

https://github.com/codr7/liblg/blob/master/bench/fibiter.py

https://github.com/codr7/liblg/blob/master/bench/fibtail.py

Re:Thinking About Recursion by tgv on Monday October 12, 2020 @02:04AM (#24751818)
The point of recursion is not recursion, but a better way to write code. Better can be more readable, less errors, whatever, but adding two parameters to the Fibonacci function for the sake of introducing tail recursion, where even iteration is more understandable, is pointless.
Re:Thinking About Recursion by codr7 on Monday October 12, 2020 @02:56PM (#24758033)
Depends, not all languages provide variables and since they're more or less equal it's a matter of preference in other cases.