Sunday, 3 November 2013

A Love Letter To Recursion

I know I just recently talked about recursion in a post, but I have heard too many complaints about recursion lately to not address it.
I understand that loops are a comfort zone, but that doesn't always make them the easiest way to solve a problem.  I will admit it takes a while to get use to the way to think for recursion, but once you get it, it brakes down problems really easily and clearly. During the lab last week, the last question was solving the first question without recursion. With loops it took me an hour and a lot of lines of code, whereas the recursive algorithm took me under 15 minutes and only a few lines.

Dear Recursion,
Let the haters loop. They are just stubborn in their coding practices. If they just got to know you, they would love you like I do. You run so elegantly and are truly beautiful. You do so much with so little, it's amazing. The base case for my love will always return true for you.

2 comments:

  1. Wow I totally agree, recursion was tricky at first, but now I can't stand the thought of using loops to replace a recursive function (I released a heavy audible groan when I saw exercise 6). How did we ever code anything before recursion?
    p.s. Recursion seems to be my main blog topic as well, I guess it's just such a big part of the course!

    ReplyDelete
  2. Here is an interesting fact - NASA prohibits recursion in their code. Think about unpredictive nature of recursion. Although, it would be funny to see the Mars rover crash due to "max recursive depth exceeded" error.

    ReplyDelete