Friday, 27 February 2015

Recursion and why I don't like it

Recursion is a computer programming technique that is very similar to dividing and conquering. By breaking down the problem into smaller and smaller problems recursion can be a very effective tool to solve problems. My main issues I have with recursion are that it's difficult to read, it's hard to create a mental image on how it works, and it is proving difficult to debug. I propose iteration should be used whenever possible.

When reviewing code that was written in lecture, code found online, and collaborating with friends it can be very difficult to fully understand how the program works. I think this is because with how the code is displayed. With iteration you can see exactly what the algorithm is looping over and what is happening in each loop. With recursion it is difficult to see when your loop is going to end.

My next point also goes in hand with my previous one, it is very difficult to create a mental of map of how a program is looping recursively. This may be a matter of familiarity but I personally find it insanely simpler to visualize a iteration.

When given buggy code that utilizes recursion it can be very challenging to find where exactly the problem is. With iteration debugging can be hard, but using breakpoints, tracking variables and other simplistic strategies, it is easier to find the exact where there's a problem.

I have also experienced and read about cases where recursive loops can spiral out of control. Eating up time and memory. While recursion in some instance maybe better in some instances, I think it's a safer strategy to use iteration where ever possible.

No comments:

Post a Comment