Hacker News new | ask | show | jobs
by vessenes 5367 days ago
Is there a reason that these examples are using some sort of deeply nested call stack? Is it just to enforce 'slowness' in the function calls?

  def fibonacci(n):
    a,b = 0,1
    for i in range(0,n):
     a,b, = b,a+b
  return b
(cadged from zacharyfox.com) performs far, far better than the nested function calls. I imagine it would in javascript as well. In python at least, all that function calling infrastructure is relatively expensive.
2 comments

It's just a canonical form; it's far easier (IMHO) for a beginner to understand a recursively written Fibonacci number computer than your function.
I hear that. In this case, though the entire blog article was complaints about slowness, or blocking behavior as seen through slowness.
> Is it just to enforce 'slowness' in the function calls?

Yes. He was just illustrating a point about blocking on the CPU.