Friday, January 31, 2014
Wednesday, January 22, 2014
Week 3
This is the first entry of my sLog. The instructor asked us to write a paragraph on object-oriented programming. I haven't really learned much about object-oriented programming before, however, I've seen this phrase many times. I guess that it is a very fundamental and important topic in programming. Basically, from my understanding, the object-oriented programming we are doing is very much about creating new object (i.e. creating new class).
In the first two weeks of CSC148, I've learned some new material regarding object-oriented programming. We started with design of a new class, which is slightly different comparing to how we did it in CSC108. The first difference is the header. We now integrate the type contract into the header. I started implementing this when writing the first exercise. This change makes the code look more neat and concise.
I also learned many more new approaches. Most of them are not difficult to understand. One is "list comprehension", which is a very convenient way of writing code, in the form [expression for x in iterable]. With this method, a lot of tedious "for loops" can be eliminated from my codes. I also found that "isinstance(...)" is super helpful. For example, 'isinstance(other, Point)' checks if 'other' is an instance of class Point. I can then easily identify an object in any class I write.
A very new new topic to me is raising an Exception, and how to create a new class of Exception. I found that the process of creating a new class is very straightforward. But the difficult part is to figure out when to raise an exception.
The most confusing part is the problem with attribute access. I did not get it during the lecture so I reviewed the slide to understand it. We put the underline in the variable, (ex. self._coord), which indicates the attribute is "private". The builtin function property then intercepts to avoid modification to coord. I also discussed with my friend further on this problem as we both found it unclear.
Subscribe to:
Posts (Atom)