Hacker News new | ask | show | jobs
by rapala 4366 days ago
Here's the same in Haskell:

  doDishes []            = done
  doDishes (dish:dishes) = clean dish >> doDishes dishes
Very much a recursion in my opinion.

Recursion can cause stack overflow in lazy language too. But lazy or strict, that's more of an implementation detail although a very visible one. An iteration that appends to a list will run out of memory just the same. I also don't see how a recursion that runs out of stack space is any more dangerouse than an iteration that goes to an infinite loop.

1 comments

That is just a loop in my opinion; it would be easier and more clear to express it as a loop. The power of recursion isn't really necessary, nor is it somehow more enlightened.

Exhausting your call stack in most languages is really bad as far as debugging is concerned: it loses the ability to even form a decent error message (stack overflow), and you are left with poor content for diagnosing the problem. Exhausting the heap or having an infinite loop, in comparison, are vastly easier to debug (the latter being much easier than the former, thrashing the VM system is also a pain in the arse, though less so than exhausting the stack).