Saturday, 19 October 2013

OOP + Recursion

Having taken a programming course before in high school, this wasn't my first exposure to OOP (object oriented programming). I've never learned another style of programming, so I can't imagine why there would be another way that could work better. OOP makes a lot of sense in connecting the way we program with what we're familiar with in the real world. You have an object, which has attributes and can behave in certain ways. I believe anytime we can connect something abstract (such as programming) with something concrete (things we can interact with in the real world), it makes a lot of sense to do so. It increases understanding as our brain always wants to connect something new to something it already knows. Not to mention all of the organization that OOP brings to the table. Software development almost always requires a group of programmers, which means your code will need to be interpreted by others and you will have to interpret the code of others. If you know code has been written object oriented, then you know where to look for what, and you have a better idea of where to search for errors when they come up. I'm sure OOP has many more benefits that I'm not even aware of yet, but what I've mentioned is compelling enough for me to enjoy using OOP.

Recursion, however, was a different story... I'd never learned recursion before and definitely struggled for the better part of the month to figure it out. I can't say I'm an expert yet, but I have come far from my first week of class. Even before recursion, I had never heard of list comprehensions before. Now, I can't even fathom writing out a 3 line for loop when it could be done so simply! Recursion is even more amazing. I still look at my recursive methods in wonder, as they complete so much with so little code!

Recursion is difficult because I was so used to iteration, I tried to understand recursion by imagining the program iterating in some way, which just led to much confusion and misinterpretation... Another problem is getting bogged down by trying to track down exactly what the program will return each time. The 'black box' way of looking at things really helped out here. Think of the base case, and when you write out the recursive method, imagine that the rest has already been solved. It's as easy as that! Well... almost. But my struggles with recursion are definitely diminishing, and it feels great to have another weapon up my sleeve for tackling future problems, whether they be of the programming type or any other.

No comments:

Post a Comment