Thursday, January 30, 2014

Test, Test...Revelation!

I usually try to have a positive outlook on my academic life yet it is only the 4th week of the term and everything has already started to pile up and get more complex.  However, it does help to remind myself how much I like a good challenge!  I look forward to the lab section of this course because my lab partner and I tend to stumble upon little tips and secrets here and there as we figure out the problems given to us.  What we discover usually helps me tremendously in comprehending the material during the rest of the week. 

 This week for example, we were working on classes, subclasses, inheritance and testing of code.  As we unravelled bits and pieces of the code, we followed the logic we usually use and then we reached the step where writing a testing method was necessary.  Contrary to what we thought was a basic problem, my partner and I faced a dilemma that had us blankly staring at the screen for over 20 minutes.  As instructed, we had created a subclass in unittest.TestCase then we wrote the test methods and gave them logical names that easily referred to their purposes.  As we ran the program though, the tests simply didn’t run!  We double-checked the syntax of our code, we asked for the TA’s help, and then out of despair, we even re-wrote the entire thing with a fresh start.  But we still couldn’t pin it down.  “What are we doing wrong?”   Little did we know that a testing method in a subclass of unittest.TestCase had to start with the word ‘test’!  In other word, the name of the method must be in the form testName, where “Name” is whatever you wish to call that function.   This was especially fascinating to me because I never thought that a function’s name could have an effect on its running abilities! 

Thursday, January 23, 2014

Object-Oriented Programming

Object-oriented programming, also known as OOP, is a computer programming approach that represents abstract ideas and concepts as ‘objects’.  I personally find this fascinating perhaps due to striking similarity between the normal flow of human thoughts and this programming paradigm; people like to think in terms of objects and now programs get to follow our lead!  Things known as ‘classes’ within OOP encompass attributes, methods and variables which are all found to better describe an object.  To put this more concretely, you may think of an object “blue jar” which is of class “Jar” then you can assign your blue jar a method to open it, another one to pour its contents, and so on.  Your blue jar will have all the features a typical Jar has.  I normally like to think of a class as a template which leads to the creation of an object allowing it to inherit that class’s properties; its attributes.   In some cases there may even be sub-classes within a class forming what is known as a class hierarchy.  This gives on a glimpse of the level of complexity within OOP which largely resembles our real world systems.   It is worth mentioning that OOP is widely used across different programming platforms including Java, Python and PHP.

I find that object-oriented programming creates easily-edited, high-quality software to solve problems, albeit not all problems.  Some programs cannot be accurately coded to work using OOP and this is where an alternative such as functional programming may be used instead.  The complexity of OOP and thus the necessity of foresight may require a programmer to put an extra amount of work on an otherwise basic project.  With its ability to refer to the type or class of an object as it is processed (polymorphism), OOP may avoid errors of misattributing objects to the wrong classes.  I believe that the encapsulation feature within OOP, where certain components of the object such as methods are restricted and secured from unauthorized access, makes it worthwhile.    OOP allows new objects to be created and old ones to be manipulated and reused by other programs thus facilitating the enhancement and “recycling” of code by future programmers.  I must confess: finally grasping the concept of objects interacting with each other to make a program run was a milestone for me at the beginning of this term; I used to be irritated by its logic but applying its concepts to the real world has helped make it far less abstract.