2
zen29d
5y

Who the fuck invented recursivešŸ˜”, it sucks in numerical computation, it takes excessive amount of memory, recomputation and fffffffuckšŸ˜”. To calculate fibonacci of 50, it feels like MARK I. fuck they do nothing more than calling, like Peter calling Peter...šŸ˜”

Comments
  • 1
    Am I missing something?
    You’re not exiting the loop, are you?
  • 0
    Aha.. Never mind.

    Please, please please, put some comments in your code if oh make it that complicated..
  • 0
    it has exit, the function calculated for other
  • 2
    well it's just not the right tool for the job here. besides, it does make it easy to understand for humans/mathematicians
  • 1
    I think the recursive one is easier to understand here, but that's because you overuse python's line-saving tricks that harm readability to compress code (why is beyond me).

    Generally speaking, recursive is good when you need a stack. So, depth first traversal, and not much more.
  • 1
    Sorry but I can't agree with your rage against recursion: it eats up stack only if it's not tail recursive (or if the language does not support tail recursion), and it is slow only if the algorithm is not optimized (which is the case for the naïve Fibonacci implementation). You can easily write a recursive implementation of your example using a for loop with range(). (Though I'm not into Python enough to give you an example in that language off the top of my head.)
  • 1
    Addendum to my previous comment: Here's an example in F#. Since text formatting sucks in the comments, I have two functions in the same scope but the helper function can easily be made local to the main function.

    let rec fibloop n a b = if n > 0 then fibloop (n - 1) b (a + b) else b

    let fibrec n = fibloop n 0 1
  • 0
    @SomeNone : I've used both the loop one and the recursive one... for small calculation recursive is okay... The recursive function doesn’t reduce to a smaller subproblem, so it doesn’t converges. Consider tower Hanoi eg: "Assuming the monks move discs at the rate of one per second, it would take them more than 5.8 billion centuries to solve the 64-disc problem."
Add Comment