Wednesday, 22 January 2014

Object-Oriented Programming

     Having worked with the concepts of inheritance, composition and exceptions in the past, the third of week of CSC148 felt like, in general, an effective and comprehensive review. Being new to Python, it was, as one might expect, interesting to compare the ways in which Python implements these programming concepts in contrast to other OOP languages like C++ and Java.

     Generally speaking, I find making use of classes in Python to be easy and intuitive. I particularly enjoy the way in which Object-Oriented Programming works to structure my solutions in a coherent manner - for example, instead of outright treating an ADT, like a list, as a stack, it is much more intuitive to encapsulate all methods related to stacks in a single class and then call on that class as needed in the future. 

     I felt that, not only is it less tedious to code in such a paradigm, but it is also easier to understand and make future use of chunks of code relating to a particular ADT or set of methods (i.e. stacks, queues or a class of mathematical operations). In other words, the aspect of reuasbility - just as in procedural programming - is perhaps one of the most appealing features of OOP. In summary, the amount of structure and coherence that  OOP brings when coding a solution to a problem is what I think is the most enjoyable aspect of coding with an OOP paradigm in mind.

     Now that my general overview/ analysis of this the OOP discussed thus far in the course is over, I will now move on to some challenges that arose during my experiences with OOP in these first few weeks.

     My first challenge was centered around the concept of 'flexibility' of my classes: How might I structure my classes in way where others, and myself, could use those same classes for solving a variety (of different) problems? What I mean is this: I know that I am writing a certain class to help with my solution to one particular problem, but isn't one of the central ideas of OOP reusability? Will this same class benefit me in other cases, or will I (or others) need to modify it later to suit my (new) purpose? 

    What these questions lead me to was the idea that, when I write my classes, I should bear in mind  different ways in which someone (or myself) might want to interact with this class. I should then code my classes in a way that is not just tied or suited to the problem at hand - i.e. I should include helpful methods that can may be used to manipulate the class in different ways than what I currently need. Of course, I needn't stress over every possible use of this class but, at the very least, the class should be (except in special cases) general enough that it is able to be used in different ways.

     Am I putting too much emphasis on reusability? Perhaps. But I believe firmly that this should be an idea at the back of the mind of any serious user of a OOP paradigm. 

     I will mention one other OOP challenge I encountered these past few weeks: the fact that, unlike C++ or Java, Python does not consider access levels in classes (private, public variables etc.). This is a concept that I learned to work with when I first started with the OOP paradigm in other languages - and it is a concept that I stuck with throughout my studies in computer science. 

     Though it is not a major issue, I know that it will take me a while to adjust to thinking object-orientedly without considering access levels, I feel that it also somewhat liberating to know that I don't need to worry about programs that might access a variable their not supposed to and hence, not use the class as intended. On the flip side, I will need to more careful when I use my own (or other's) classes!



2 comments:

  1. Interesting stuff man I may want to take up your view on reusing your programs later in the future.

    ReplyDelete
    Replies
    1. Glad you found it interesting (though I may have written *a bit* too much - thanks for reading through it!)

      And yes, re-usability is one of my favourite programming features; it really makes your solution look more elegant.

      Also, thank you for the comment - much appreciated! :)

      Delete