Thursday, January 23, 2014

Object-Oriented Programming

The first three weeks of the course have explored the subject of object-oriented programming. We have been learning about classes, which is what we ended with in CSC108. Personally, the class system is way more enjoyable than learning basic programming skills. Although it was tedious to learn the basics, especially with a decent amount of knowledge prior to taking the course, I'd say that 108 showed me how to create efficient code with enough style to prevent confusion.
Object-oriented programming focuses on the creation and programming of objects. These objects, such as Dog, can be created with the class system, where you can assign to it different attributes inside the __init__ method, like name, type, etc. Within these classes, methods can be implemented to manipulate its attributes. These methods are typical functions, but they are accessible by typing object.method(x) inside the shell. For example, if we have an object Phone, we can write a method Call(self, person) to call a person, producing a string of a conversation. To further understand the meaning of object-oriented programming, a reading from the first week provided a straightforward description: "In procedural programming the focus is on writing functions or procedures which operate on data. In object-oriented programming the focus is on the creation of objects which contain both data and functionality together." Exercise One tied in perfectly with the quote above. The exercise gave us the task to write a Dog object and a Toy object, and showed how their unique methods allow these objects to interact. I prefer object-oriented programming because it feels like I'm actually manipulating something substantial or valuable. While, in procedural programming, it felt like I was inputting arbitrary values into functions, which were often confusing and scattered all over a python file, to see what they would produce. Now that I know the basics of Python programming, I think I'm ready to tackle bigger, more rewarding tasks.

*Notable readings: Object-oriented Python

No comments:

Post a Comment