Wednesday, 4 March 2015

Week7 - Recursion

We have leant about recursion for a few weeks. Recursion means "defining something in terms of itself", a recursive function can call itself to solve other small subproblems. I was fascinated when I first saw the recursive function example my professor showed:
def sum_list(L):
    """
    (int or arbitrarily nested list of int) -> int
    
    Return the sum of all ints in L.
    
    >>> sum_list([1, [2, 3], [4, 5, [6, 7], 8]])
    36
    """
    
    if isinstance(L, list):
        return sum([sum_list(x) for x in L])
    
    else:
        return L
    To understand recursion, we need to be able to know how it works. As the above illustrates, when the function runs, it will first check if L is the type of list; so the function will call itself to check the terms in the list. Therefore, after a few steps, L will be converted to the following:
sum(1, sum([2, 3]), sum([4, 5, sum([6, 7]), 8))
Therefore, the function will return the result "36".
    Tracing recursive function help me a lot on understanding the concept, it also teaches me how to analyze each step of the recursion. 






Citation:
"18. Recursion." 18. Recursion — How to Think Like a Computer Scientist: Learning with Python 3. N.p., n.d. Web. 04 Mar. 2015.

Week6 - Summary of Object-Oriented Programming Concepts

   Object-oriented programming is a "programming language model organized [mainly] around" object and data (Rouse Margaret). Object-oriented programming centers around the objects we want to "manipulate" more than the "logic needed to operate them (Rouse). Sometimes we want to manipulate objects from the real world such as a record or a registry, which are not described in Python, we can create classes and subclasses for them. And this process is OOP.
    The first step in OOP is to make sure the what are the objects that need to be manipulated and the connections among them, which is called "data modeling" (Rouse). After the class of the identified object is created, the programmer will then design all the necessary methods that help manipulate the object inside the class. Sometimes the object needs more than one classes and subclasses, but that depends on how the programmer wants to manipulate the object.
   


Citation: 
Rouse, Margaret. "What Is Object-oriented Programming (OOP)? - Definition from WhatIs.com." SearchSOA. N.p., n.d. Web. 04 Mar. 2015.

Tuesday, 3 March 2015

Week5 - Tracing Recuesion

    Last week we learnt about recursion and how to trace a recursive function. I was fascinated when I first saw the recursive function example my professor showed:
def sum_list(L):
    """
    (int or arbitrarily nested list of int) -> int
    
    Return the sum of all ints in L.
    
    >>> sum_list([1, [2, 3], [4, 5, [6, 7], 8]])
    36
    """
    
    if isinstance(L, list):
        return sum([sum_list(x) for x in L])
    
    else:
        return L
    To understand recursion, we need to be able to know how it works. As the above illustrates, when the function runs, it will first check if L is the type of list; so the function will call itself to check the terms in the list. Therefore, after a few steps, L will be converted to the following:
sum(1, sum([2, 3]), sum([4, 5, sum([6, 7]), 8))
Therefore, the function will return the result "36".
    Tracing recursive function help me a lot on understanding the concept, it also teaches me how to analyze each step of the recursion. 

Monday, 2 March 2015

Week4 - Impression of first few weeks

    The first few weeks were kind of tough for me since we have been taught quite a few new concepts. Different from csc108, csc148 is much more challenging. In csc108, we started from something very basic such as float, int and str and the structure of a function. In csc148 we started from class and our first assignment is to program by using classes.
    In the first assignment, we were asked to design a game. When I and my teammate first get the handout, we had some hard time understanding it. It really took some getting used to for us because we need to plan what we need to write to make it satisfy all the requirements; however, in csc108 we were given all the functions we need to write and we just need to complete the function bodies and doc strings. After we almost finished, we found out that we only had four classes, but we were supposed to have five classes. Therefore, we rearranged almost every functions. In my opinion, the game_view class is the most challenging and tricky because it is the class that connects everything together and make the game work. Fortunately we got everything worked out and submitted the file in time.
    All in all, I found the first few weeks were a bit challenging, and I am planning to spend more time on the csc courses.

Thursday, 22 January 2015

Week3 - Why geeks should write

    It is important for a computer programmer to know how to write because a good programmer should be able to not only create brilliant code, but also express their ideas to others. If a programmer writes well, others then can see the values in the code so that instead of rewriting it, they can work with it (Joel Spolsky).
    Another reason why programmers should write is that writing debugging journal is also crucial. When a programmer gets stuck when writing a code or finds the code result in some errors, they can record down the problem and the process of soling it. Besides, the programmer "will have something to refer to if [one] cannot remember" how to fix that bug (Steve Rydz). Last but not least, the journal can somehow force the programmers to understand how the bugs get fixed (Rydz).
    Writing is a way of communicating ideas, which can makes a code much more useful. Therefore, writing is one of the indispensable skills a great programmer should master.




Citation:
Rydz, Steve. "Steve Rydz." Keeping a Debugging Journal. N.p., 19 Nov. 2013. Web. 22 Jan. 2015.
Spolsky, Joel. "Joel on Software." Advice for Computer Science College Students -. N.p., 2 Jan. 2005. Web. 22 Jan. 2015.