3 ms·
One of my favorite ways to think about recursion is that it's a shitty technique that can and will blow up your stack. When I try to solve a problem with recur
by redis_mlc 7y ago
One of my favorite ways to think about recursion is that it's a shitty technique that can and will blow up your stack.
When I try to solve a problem with recursion, then I have two problems.
It's also a great way to filter out morons in interviews. If they ask for a recursive solution, and I tell them that it's a shitty solution, and if they don't immediately agree, then I know I'll be working with morons.
- sundbry 7y agoWow. such smart. Eliet hacker. https://lmgtfy.com/?q=tail+call+optimization https://lmgtfy.com/?q=tail+call+optimization
- tigershark 7y agoNever heard of tail-call optimization, right?
- acchow 7y agoWhy are recursive solutions shitty? I find them easier to read...
- slikts 7y agoRecursion is a powerful, relatively low-level approach, and the price for expressive power is readability, but it has legit use cases. What you said has a grain of truth in that usually you should prefer combinators like map or filter (if you're doing FP), but just throwing away recursion is silly. Having a strong opinion on it and not seeming to know about TCO is also not a good look.
- zelphirkalt 7y agoI don't think it's necessarily more difficult to read, especially with the mindset of the "recursion goblins" mentioned in another comment here, where one only looks at the current iteration and does not care about, where input argument comes from. But of course, if what one wants to do can be expressed using map and filter and such, why write some recursive procedure.