Monday 3 March 2014

Recursion

After tracing and practice through a couple recursive function, I finally understand how they work. They seems to work in 'layers' (kind of like Inception). This can be demonstrated with the first recursion we did in class, the sum of the nested list. For example, if the nested list is [1,[2,3,[4]]], the function calls itself again if it encounter another list, like going into layers after layers. So recursion is very good with  list within list, or more generally, it is very good for accessing information of an object within another object for our uses purposes. Another example we encounter is Trees, in order to access the information of a tree (its nodes), we can express the leaves of a tree in nested list, which can be access using recursions.

Tuesday 21 January 2014

Object Oriented Program

In CSC108, I have always wonder, where do all the methods come from and how to they work. Now, in CSC148,  I have learned how to create classes, and writing method for them, which answers the 'mystery' for me. I found classes very useful, because we can take the existing classes in python and develop it more so the class fits our requirement. Also, I have also learned a very interesting way to be 'lazy' in coding by using ternary if and recursion.