Recursion works for computer science classes, as a way of misleading dev students about what actually goes on in software development.
In industry I’m not sure if I’ve ever seen a recursive function written by anyone other than a total beginner.
Recursion makes debugging extremely difficult and problems which are suitable for recursion can often be solved by having two functions and a couple of variables about state. One function manages the state variable and the other function actually does processing and the managing function has a loop that updates the state variables and keeps calling the processing function until the state variables represent a success state.
There is another use for recursion in industry which is when a tech company wants to know how good you are at writing unreadable, untestable, confusing “genius code”, they’ll give you some recursion problem to try it with.
Latest Answers