Sunday, 13 October 2013

Week #5

I've only ever blogged once before so I'm kind of new to adding updates and general changes throughout the week. Anyway that first assignment was interesting. It didn't pose too much of a challenge, thankfully, except for creating a general recursive function that would work for an n amount of stools. It was an exceptionally clever assignment though; teaching two important concepts all at once through the Canterbury tale of Anne Hoy and her cheese problem.

What is this 'recursion' everyone so often speaks of? 

Recursion is an unusually simple but difficult concept to grasp. It’s an extremely efficient way to handle certain situations but is often neglected or overlooked. My programming teacher in high school always said “You either understand recursion or you don’t. Usually it just hits you one day and you get it”. The “What is recursion?” question is regularly asked by programmers. If you search on Google, you get a variety of answers ranging from “Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem” or “Recursion is the process of defining a problem in terms of itself”. In other words, recursion is a function that calls itself a number of times.  It is important because it allows programmers to efficiently solve a mathematical model/algorithm that has definite boundaries/parameters. There are a variety of examples where recursion would prove handy such as; traversing trees, modelling mathematical formulas such as factorials (our Towers of Hanoi algorithm too!), fractals, etc. Recursive functions are usually easier to read and understand than solving with loops. Other benefits are that it’s simple, uncomplicated, and time-efficient as opposed to loops.

What's so special about Object Oriented Programming?


Object oriented programming (OOP) is a very important concept to grasp because, as has been mentioned so many times before, it allows us to model things from the real world. In our world, we don’t just deal with procedures but we deal with objects that have specific characteristics and functions. Methods and attributes of classes are extremely useful for distinguishing what is unique to our object compared to others. Attributes are characteristics of the real world object such as eye colour and methods are actions that a real world object may take in response to a call such as barking. This is beneficial since, as can be seen in our first assignment, we were able to create objects of CheeseView, a class inheriting from cheese, containing characteristics such as size and methods like place to represent Anne Hoy’s situation. We didn't want our cheese to know how to move itself across other stools in optimal moves, we wanted it to sit there like a cheese would. Encapsulation is also an important aspect of OOP since it allows you to hide data so as to prevent unwanted modifications from the outside. We don't want our solver function messing with the size of our cheeses, that'd just be crazy.


Though I hope our future assignments will be a little simpler, the recursive function for 4 stools was a real mind twister. At least all that head banging turned out to be for good use.

No comments:

Post a Comment