During college recursion was always on a pedestal where only good programmers used and understood it. I got the basic idea, but never fully understood how to use recursion effectively. This always dug away at my confidence as a programmer.
Since, working in the field and becoming more aware of literature in the field I have come to realize that the use of recursion does not make you a good programmer.
Recursion tends to add complexity when a simple for loop would do the job. There are of course times that recursion might be the best solution, however, one must consider the trade-offs between readability/complexity and efficiency.
I have never used recursion in practice. The only times I have used recursion was when learning what and how it works in college. I would like to find in instance where it makes since to use, but higher level languages tend to restrict your options to enhance readability and structure.
I for one prefer readability over elegance.
Things to consider when using recursion from Code Complete (page 410):
- Does the recursive routine include code to stop the recursion?
- Does it use a safety counter or guarantee the routine stops?
- Is recursion limited to one routine?
- Does the depth of the recursion stay in-bounds of the program’s memory?
- Is recursion the best approach? Is it better then simple iteration?
Please remember that, it doesn’t matter what your code looks like if it is not being used.