Thursday, January 23, 2014

Week 3 OOP

Since I have little idea about 'non-object-oriented programming', if there is one, I cannot really fully understand what's special for object-oriented programming and under what circumstances it will be used. 

Using my intuition and the knowledge that I possess so far, I think object-oriented programming is a type of programming language that has something to do with objects. For example, every line of code we wrote contains one or more objects, like strings, lists, numbers, dictionaries, tuples, and even new classes created by ourselves. And we can use object-oriented programming languages such as Python to create some functions or methods to solve problems containing objects.

This week, I learned several concepts in class, like raising an exception and creating a new class called Stack. The class Stack have many functions. For instance, it can store some values in a list as well as removing values from the list. In the lecture, we also came up with a way to create the Stack object correctly even when we type s = Stack([1, 2, 3]) whereas s = Stack() is how we originally create the class Stack.


I think week 3's lab was fun, especially the efficiency improvement part. At the beginning, my codes needed more than 4 seconds to run the most complex test. After I improved my codes with the help of TA, I could run the test only in 0.2 second (or 0.02...I forgot). When I achieved that after spending 40 minutes of thinking, I was really happy. The way I did was to add a new variable in the __init__ method to keep tracing the time that the method dequeue() is called. So every time the dequeue method is called, the object at the index that is traced will be returned instead of using pop at the beginning. This method can increase the run time of the program a lot shorter.