Total Pageviews

Friday, 11 October 2013

Self-Reflection + The importance of Object-oriented programming and Recursion!

One thing that has struck me this past week has been the fact that group work is highly important in programming....more important than I thought previously. This thought came as the deadline for assignment one was looming and I was still stuck on tour.py. In a group, team members are much more likely to catch silly mistakes other team members make on their code.

The labs for example need to be completed by a group of two students. One student acts as the driver (writes the code) and the other student acts as the navigator (reading out the design recipe and making sure there aren't any mistakes being made). This relationship as first did not have much significance for me but after making so many silly mistakes and wasting time figuring out the silly mistakes I could have been much faster with completing my assignment if I had chosen to have a partner.

Now on to a completely different topic! Object-oriented programming is rather new for me. I started it briefly at the end of csc 108. Now that I have really gotten a taste of what Object-oriented programming is about I can give my thoughts about the topic. For simplicity sake I will abbreviate Object-oriented programming as "O-op".

O-op gives the programmer much more control over their code. Just relying on python's built-in functions can be rather troublesome as many of the built-in functions have attributes that perhaps you do not want in your code. In O-op you create an object and give it certain attributes. For example when creating a program you have a list that perhaps you do not want being altered in a certain way. A normal list would have the built-in function (append(), pop() etc). But in a O-op you could have a list which cannot have its items be removed. A regular python list can have items added to the front or the back. Perhaps you only want new items being added to your object from the front. In that case you would give your class a method which adds new items to front. If anyone uses your code and tries to append an item to the back, they would raise an exception or get an error. For this reason and many more O-op is a much appreciated method for programmers wanting more control over their code.

In addition to O-op another important wonderful thing has happened. I finally learned recursions. Recursions are loops where a function calls itself in its own function body. At first it was hard to understand how such a thing was possible. But after numerous examples it slowly becoming more and more understandable.  Recursion first of all is important because of its simplicity. The code can be so simple yet to powerful. If you have a function which finds the maximum number from a list of numbers, it becomes a problem if there is a list of numbers inside the list of numbers. Obviously an error will occur in a simple code. But with recursion the program can literally call itself and find out the maximum number in the inner list and then compare it to the numbers in the outer list. Recursion is also needed when creating a tree. A tree looks really complicated when you are trying to create one without recursion, but with recursion the process feel a lot more easier.




1 comment:

  1. Excellent post! Note that the "official" abbreviation for Object-oriented programming is OOP.
    If you create any neat objects, it would be great to see your code up here

    ReplyDelete