7 ms·
Recursion is as hard as mutable state to grasp if not harder. We might find a few people who can do one thing sligtly better than the other one, but not complet
by guard-of-terra 12y ago
Recursion is as hard as mutable state to grasp if not harder.
We might find a few people who can do one thing sligtly better than the other one, but not complete blanks.
- duaneb 12y agoI disagree. Recursion is simply inductive reasoning, which people are able to grasp at a young age.
- Morgawr 12y agoThe whole point of what I said is that "hard" is a difficult thing to judge. For some tasks and some languages recursion is much easier to understand, teach and use. Just take the good ol' classical example of quicksort in Haskell or fibonacci in Lisp. Some people can grok recursion in a functional programming language much faster and more easily than they would understand the concept of branching, variable assignment (with mutability) and non-pure functions (what we used to call "procedures" back in the day).
- kyllo 12y agoJust take the good ol' classical example of quicksort in Haskell or fibonacci in Lisp. Hell, recursive quicksort and mergesort are easier to teach and remember than the iterative versions even in C and Java. They're divide-and-conquer algorithms, which makes them a natural fit for a recursive solution.
- splinterofchaos 12y agoThe classic C/C++ versions are recursive, and using the STL, c++'s quick sort looks very similar to the functional one. From cppreference.com: http://coliru.stacked-crooked.com/view?id=0b2cec4d8c69ffaf http://coliru.stacked-crooked.com/view?id=0b2cec4d8c69ffaf http://en.cppreference.com/w/cpp/algorithm/partition http://en.cppreference.com/w/cpp/algorithm/partition
- rebootthesystem 12y agoIn 35 years of programming across platforms and languages covering embedded to web applications it is my opinion that recursion is dangerous and useless. There is no way I would use recursion to evaluate how good a programmer might be. To quote the movie: "Frankly dear, I don't give a damn".
- mytochar 12y agoWhy?
- rebootthesystem 12y agoJust so I can answer, why what?
- rebootthesystem 12y agoJust in case this is what you were trying to understand: https://www.google.com/search?q=recursion+is+dangerous&rlz=1C9BKJA_enUS590US591&oq=recursion+is+danger&aqs=chrome.1.69i57j0&sourceid=chrome-mobile&espv=1&ie=UTF-8&hl=en-US https://www.google.com/search?q=recursion+is+dangerous&rlz=1... http://m.slashdot.org/story/198499 http://m.slashdot.org/story/198499 You can certainly dig up more information. For me, and this is just my opinion based on 35 years of software and hardware engineering, recursion is a neat academic idea but in the real world it is useless and dangerous.
- mytochar 12y agoI'm seeing stack overflows (not a problem with tail-call optimization) as the biggest problem here. There are equally dangerous problems, though. Buffer overflows are a very real concern, especially in embedded software; but that doesn't mean that people don't ever use pointers. Everything about software has risks. Yes, they probably shouldn't have used recursion there in that car; but honestly, it's just a stack. Enough calls and some state could have been frozen. They should have put mitigations in place to stop the potential for a stack overflow to have actual, detrimental results. Do you refuse to ever make a function call for fear that you might be at the top of the stack somehow? After all, how can you know that you haven't accidentally created a state machine with function calls and are at the peak of it now, and end up causing the same problem. Recursion may have been the final manifestation, but it's certainly not the only place that failed. I argue against your thought that recursion is useless, as well. It's a natural and intuitive solution for a lot of problems. The very concept of a dynamic programming solution starts with a recurrence relationship. It starts with recursion. Sorting algorithms are intutively recursive in many cases, Quicksort and Mergesort are just two examples. And, 'dangerous' is an interesting term. I understand you've worked in embedded systems and hardware, and so those things are often critical systems that have to be super secure and completely bug free. Not every system is like that, though. I want to understand why you believe that recursion is both useless and dangerous. Could you give some broad examples of the dangers of recursion from your years of experience?
- rtpg 12y agomaybe the initial concept, but what is easier to debug afterwards? So much teaching material for beginning programming is tainted by the cult of mutability that I have coworkers writing for loops instead of maps or the like for relatively trivial tasks. The end result is I have a harder time reading code, and the amount of possible bugs grows.