Wednesday 9 October 2013

Recursion

I've already talked a lot about recursion in my previous posts, mostly because it has caused me so much suffering over the past few days. However by the end of assignment A1 (the very end, see my first post as to how close I cut it), I got it. Recursion is only as useful insofar as you understand it. You have to be very careful to pass information up and down the trees; if you mess up, errors can be very difficult to rectify. In simple terms, recursion is when a function calls itself- however as by calling itself, it calls itself again, you can very easily create an infinite recursion loop. Luckily there is a maximum recursion depth to prevent the system from completely crashing. However, if you can successfully impose conditions to end the function, then you can use it to drastically reduce the number of lines of code you have.

Object Oriented Programming

As per Danny's request, this is a short paragraph on the uses of Object oriented programming. Now, I have come to realize what that means. EVERYTHING is an object. You can call anything by creating a new object which is given attributes by the function. This is particularly confusing when using recursion, as separate namespaces are generated with their own distinct objects. However, the advantage to object oriented programming is that everything can be kept track of. You can retrieve any object you've created using a single line. You can create several instances of something, meaning that you will have two identical objects, and then change the attributes of one and compare it to the other. All in all, object oriented programming can be confusing but once harnessed, can be extremely powerful.

First Post- Recursion Confusion

Hello World!

First of all I would like to apologize for not publishing until now- I simply did not have the time. Life has been excruciating, exhilarating, and exciting.

But this blog, or slog rather, is not about my life; it is about one aspect of my life, namely CSC148 which is eating up quite a bit of my time.

Yesterday, our first big assignment was due, solving the Towers of Hanoi problem with 4 stools instead of the standard three stools with the minimum number of moves.

This assignment was BRUTAL! As someone who is very rusty with coding, with no experience in python, recursion is something I have yet to truly explore. What an introduction! Every step of the way I was confused. Every step of the way I had about 10 million errors which took hours to correct. And yet, every step of the way I learned so much about programming.

Recursion is tricky; solving even the three stool Towers of Hanoi problem is not a walk in the park (for me- as with every U of T course I'm sure CSC148 is littered with geniuses for whom this assignment was easy as pie).
My aerospace Engineering Science roommate walked in and told me that when he first learned recursion, he learned it using the 3 tower Hanoi problem. He also told me that he didn't fully understand it.

Now I'm not used to python at all. I missed both rampup sessions due to previous engagements, so I started this course off very badly. I barely made it through the first three exercises, and even struggled with the labs which in relation to everything else, are pathetically easy.

After this assignment, I feel like a python guru.

There is nothing quite like failing a thousand times at something in an effort to understand it. 4 hours before the assignment was due, after already having spent almost two full days working on it, I was still confused about Tour.py.

And then inspiration hit like it has never hit me before. I understood everything; the construction of separate namespaces, the way all the variables were stored, how to store and recall variables correctly and sequentially up and down the recursion tree. Although I was unable to complete the SolvingController on time (which INFURIATED me. this part of the assignment was WAY easier than understanding Tour.py.), properly and truly understanding recursion is worth it. I don't think I'll have any incomplete assignments again in this course; this slog included.