Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@halfflat I saw an article that talked about gcc optimizations. It showed how in some cases gcc turns the recursive function into a loop. Really interesting how it smart enough to do that.
-
A few. Why the question?
Typical cases: rendering nested navigation lists, recursively reading directories, working with any tree structures -
drewbie8065y@webketje as a frontend I've never had to do it, and going into interviews having to grasp it is difficult for me. That's all.
-
@drewbie It's mainly good for depth first traversal. They usually introduce it with fibbonacci numbers, but that's actually a bad example because it is better solved with a basic loop.
-
2 or 3.
I'm really fond of recursion, my last project's main engine is completely based on asynchronous recursion. -
A lot. I mean when you are building a tree structure, recursion is a must imo because it is much more readable than other approaches.
-
@lamka02sk I disagree as a personal preference. Instead, I use a stack or queue depending on desired processing order. By doing so, any debugging deals with just a single while loop rather than a call stack N levels deep.
-
Intentionally? In 15 years, one. And I'm pretty sure the next dev took it out.
Such is life in enterprise shops. -
fuckwit12165y@hash-table well but shouldn't you do that the other way round? Generally using loops (if possible I know that there are problems that are not solvable without recursion) is more performant speed and space wise.
-
@drewbie in fact I had to do a test in an interview with a recursive function last week. It was the worst idea ever and I half-failed (had to spin up a user friendly React-Redux nested-grouped todo MVC app in 30 minutes, npm robbed me of 10). Imo if they want to test your skills like that they should give you an assignment with enough time to come up with a decent solution
-
@fuckwit If you need a stack, recursion is definitely faster since there's hardware support for the call stack. If you don't need to allocate memory, loops are probably faster.
Related Rants
How many recursive functions have you wrote at work?
question
recursive
functions