Sunday, 9 February 2014

CSC WEEK 3

This week in class, we focused on the usage of object oriented programming in Python. Since Python is an object-oriented language, this was a very useful way of organizing our code. We used the example of a Stack class to emulate a stack of real life objects. Due to the forces of gravity, a stack is not able to have an item removed from the bottom of it, but only from the top. We incorporated these properties into our Stack class using our knowledge of computer science with new material of classes.

The concept of a class was introduced to us during the first few weeks. It seems a much more logical approach to modelling real life situations than implementing code without any structure. It also is practical if one wants to use a block of code repeatedly, since all you have to do is call the class instead of rewriting lines upon lines of code. I think the implementation of classes in this course will make our future coding easier.

My adjustment to the mentality of object oriented programming was not very difficult. In previous years, I had covered the concept of classes using Java, another object oriented language. This allows me to think in an object oriented manner more easily than a beginner. My most difficult challenge was learning the Python syntax for class manipulation (as well as some more basic syntax). Since I omitted CSC108 from my courses, I had to try and remember my Python from my grade 10 programming class. Furthermore, with the update of Python 3, some syntax has been changed. I have tried numerous times(and I'm sure I will try again) to use the print function without brackets, each time leading to frustration (my tutorial partner can attest to this). Despite this, I think I should be fully accustomed to Python within the next two weeks.

One of the most interesting things about Python this week was the usage of the underscore in variable names. In Java, it was possible to create access modifiers for variables, omitting others from modifying certain variables. However in Python, the underscore is used to signify privacy. It is assumed that the user of the code would have the courtesy to not modify your variables. Another interesting part of Python is the absence of overloading methods. Python does not need to overload methods since the parameters may be of any type (yet you can still use type contracts to denote the type of a parameter). If a parameter is allowed to be omitted, it is declared as a None type in the definition. Another thing I still have to get used to is the concept of self, and having to incorporate it into the parameters. This gave me many errors during the first exercise.

For the first three weeks of CSC148, I feel that I have readjusted to the mentality of a programmer, despite my one year absence from coding. As the course continues to increase in difficulty, I hope I will be able to adjust.

Note to teacher: I am terribly sorry for the late submission of Week 3. I was unaware I had submitted it under the "Pages" category as opposed to the "Posts" one.

No comments:

Post a Comment