Sunday, 13 October 2013

Week 5: October 7 - 13

This week:

This week's exploration about recursion is very interesting: recursion simplifies code, often converting over ten or twenty lines of code into a single line of code. The main problem with recursion is finding that one line of code in the first place, it is very easy to get infinite recursion even if an ending case is used, but perhaps not all of the endings are covered.

This is the main difficulty I had with the idea of recursion, and therefore assignment 1, which used it heavily. With iterative programs, which will tell you which line of code has an error and allows you to focus upon it, recursive programs are not so easily debugged. A single line of code, forgotten case or even misplaced command can have one reading through the code for up to an hour trying to fix it. The worst case is when it works, but not the way that you expect. There's just no real way to solve this problem other than going through the program (which often requires going through the method many, many times). Therefore, though I believe recursion is great when done correctly, it is very troublesome to fix when there is even the smallest error.

Therefore, to help with this problem, I've often started at the output when writing recursive programs. While most iterative programs require thinking from the start and creating a path to the ending output, I find it easier to start at the terminating case and work backwards. This is the technique that I plan to use for recursive programs in general.


1 comment:

  1. Yes recursion is really useful since invariably recursive functions are clearer, simpler, shorter, and easier to understand than their non-recursive counterparts. I like your technique in thinking about recursion backwards .

    ReplyDelete