Friday, February 20, 2015

Impressions of tracing recursion


def depth(L):
    """
    this function returns the depth of the argument if it is a list, else 0
    """

    if isinstance(L, list):        return 1 + max([depth(x) for x in (L + [’ox’])])    else: # L is a non-list
        return 0 




    This week we traced some recursion code, the basic idea is to trace from the simplest example like when the argument return list's depth, you start with depth([]), then depth([1]), depth([ 1, 2 [ 3 ] ]), depth ([ 1, 2, 3 [ 4, 5 [ 6, 7 ] , 8] , 9 ]).  The point is for you to get the pattern of the code and what it returns, then we trace some complicated argument input, and from the previous examples, you will get the idea of how the code works.

    When you see depth([1]) returns 1,  you will know that depth([1 , 2 [ 3 ] ]) the [3] returns one then [1, 2] count as another one, so it returns 2, then you know [ 4, 5 [ 6, 7 ] , 8]  in the 3rd example would return 2, and it goes on and on.  And that is how you trace a reclusive code.


Sunday, February 15, 2015

Summary of Object-Oriented Programming Concepts

    I think the concept is really interesting.  Even though python does not have any real concept of privacy like java do(Like what this blogger says), the property and default methods are really interesting.  And all this other stuff, like raising error when you do not want the user to do anything, or inheriting functions from general class, setting parent class and children class can be a little confusing, but practise makes perfect.
 
    I did not really have a grasp of what OOP means until this course.  CSC148 has really opened my mind and view about programming.  It is not just about writing functions, it is about constructing structures and making your program faster and better.

    This is my summary for OOP concepts so far. Hopefully I will learn more as the course goes.

Sunday, February 8, 2015

More Recursion, Unit Test and Midterm Madness

    Ok, so not much happened this week, as you may know, we had midterms.  Unlike most of my friends, my midterms are all before reading week!  Not sure if that's a good thing or a bad thing to happen to me.  Upside? I have time to do my own stuff and not have to worry about reviewing for test during reading week. And the downside is that I am so busy before reading week. FML...
    
    We had one class this week and the other class we had midterm.  Prof Heap lightly touched on unit test in the lecture and some other recursion stuff, and also what is going to happen during midterm.  I was late for class because of the heavy snow we got that whole day. (The funny thing is every other school or university or campuses had a snow day, and guess what, my campus did not.  I almost got hit by a car while walking on St. George street.  Not that this have anything to do with this course, but... I just want to whine about the weather ok?!! )  The midterm was unexpectedly easy by the way for those of you who would like to have a insight on it.
    
    In this week's class, we learned more about recursion.  It is really abstract(like what this other blogger said it is some what difficult to understand if you have not heard of the concept before like me. ) I personally think if we could learn more about how to construct recursive function it would be really helpful.  Right now, it is still really hard for me to understand what it is, and how to write a function with recursion in it that works out the way I want it to be.  Overall, this concept is really interesting and I would love to learn how to use it.  We also talked about unit testing this week(? I think we did, but I cannot precisely recall what we discussed about??)  Hope we get to learn more about what we are going to do with unit test next week.

   Anyways, the course CSC148 has been interesting and challenging so far.  Cannot wait to see what is waiting ahead for us.