2015年1月30日星期五

about recursion

This week we focused on the recursion in python.
Recursion means 'defining something depending on itself'.(1)Although it can be equally written by while loops, it is more convenient and brief to use it. Nonetheless, it is a bit hard to understand at first. So we always trace it in order to understand. 
We starts from trace the code sum_list. Let's take a look at the codes below.

def sum_list(L):
    ’’’
    (arbitrarily nested list of int or 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
When we trace the code, we use some examples from easy to complicated. And we apply the result of the former examples which are easier to more complicated examples, which reduces work during tracing period. I think taking examples contributes to understand abstract codes.

(1) is from http://openbookproject.net/thinkcs/python/english3e/recursion.html
The codes above is from the handout on csc148 website.

2015年1月21日星期三

Why should geeks write?

As a typical science student, I do not have the habit of writing. Actually, it is beneficial to form the habit of writing. From some Geek forum, more and more programmers highlight the importance of writing articles.
As far as I'm concerned, writing codes have some similarities with writing articles. Firstly, no one can deny the fact that before writing we are expected to organize the thoughts. Brilliant articles have both explicit structures and the strict logic which are exactly the same with excellent codes. What's more, we need to write annotation during programming in order to help readers see how the codes work clearly. Writing articles is able to improve our skill of explanation.
What can't be ignored is that writing is in fact a procedure of thinking. We can learn a lot from thinking. We dig the things more deeply and sometimes can form a brand new insight to them. In addition, not only do outstanding writers make things easy to understand, but also express what they think clearly. This is also crucial for Geeks. For example, programmers need to let users know the function of the new app they've just write. And when the codes turn out to contain bugs, if we can express ourselves and write the annotation, others can help us more effectively.
Finally, geeks, as experts or enthusiasts or persons obsessed with a hobby or intellectual pursuit, always master some specific fields. If geeks can share what they know to other people, people will be more acknowledged and stimulated to explore the field. Commonly seen as hard to communicate with, geek can change their image by writing.