Sunday, February 9, 2014

Week 4

This week, we learned something about recursion and raising exceptions. I found recursion so amazing that it could finish many surprising things. For example, in the lecture, our professor showed us how to use recursion to draw a beautiful picture. I was totally amazed by the beauty of recursion -- it could repeat what it does for several times and make a snowflake-like things. However, because I just started to learn recursion, I sometimes found it a little difficult to understand. I also reviewed how to raise errors and exceptions and learned some new stuff like try. Try clause is pretty useful since it can raise the error without stopping the program. Another thing that's new is the function object. Now I have a better understanding of what function object is. It is not the result of a function, but just an object. It can be called just by typing its name.  

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.