Hacker News new | past | comments | ask | show | jobs | submit login

recursion overrated imo.



I disagree. To consider something overrated, its value has to be little in comparison to the effort to learn it.

For some problems, recursion is vastly superior e.g. for recursive data structure like trees. And coincidentally, often those structures are much better at delivering high-performance solutions than their naive loop-based counterparts.

Granted, it isn't easy to learn, but also not that hard. Overall, I think the gains easily outweigh the effort. And it is not like I am writing recursions all day long. Most of the time I write loops, but you should know when using recursions is the better way to go and for those times you should know how to handle them.


Note that using function-call based recursion is a programming mistake in most common programming languages, as they have a fixed sized stack.

This includes many "functional" languages like Scala. Even Haskell had a default stack size limit until some years ago, and many Haskell based parsers crashed on large inputs due to that.

If you write programs that are supposed to process arbitrarily large inputs, you cannot use function call recursion in most cases.

(Of course this says nothing about recursion as a concept, which is fundamental and unavoidable unless you're programming, say, a traffic light.)


> recursion is overrated imo

Right up until the point where you have to traverse a nested data structure.


Recursive algorithms are a natural fit for recursive data structures. Recursive Fibonacci is contrived. </cliche>


iteration gets repetitive.


recursion is full of itself, though.


iteration gets more repetitive.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: