Sunday, 29 March 2015

Week 11

I'm going to revisit the slog from week 3 on the topic of 'why geeks need to know how to write'. 
In the slog, I said that geeks need to know how to write because we could never understand programming language without knowing how to write human language. Geeks should write in order to help them innovate their programs and update errors by debugging or exchange information with others to learn from the process. After the past few weeks learning the course, I do agree with my earlier self; moreover, I think there is another reason as well. 

I still agree that writing is essential for geeks to become a success geek. I also found another reason for writing is to understand ourselves. This became more important to me than any other reason. I think I have lost myself so many times when study the course trying to understand the material, but writing helps me to organize my thoughts and understand what I want to do. I think everyone need this process to just slowdown and think about ourselves and then figure out what went wrong. Some of my friends does not like writing because they think it's a waste of time, they can do the thinking in their head. I guess it's different for everyone, but in common, we all reflect ourselves no matter it is done by writing on a laptop or thinking in their head. For me, writing on a laptop works better because it keeps track of my thoughts and I can always go back to it when I needed. This remains of the tracing when we learned recursion. We could not get the final outcome without tracing the code first, just like  I might not be able to come up with a solution when coding without understand myself first. Therefore, I think writing does helps to become a good programmer and a success or 'lazy' geeks, and the main reason is to give us the opportunity to reflect ourselves and have a clearer logic. 

Sunday, 1 March 2015

Week 7: Recursion OR Object-Oriented programming OR Abstract Data Structures

Week 7

Object-oriented programming is a very convenient way to design a program or writing a code. It takes less time and the functions looks more precise. Few important topics we encountered in the course for last few weeks such as 'class', 'subclass', recursions, and 'trees' certainly was being more than helpful once we get familiar. 

'Class' is the most important blueprint in object-oriented programming. Class logically groups related functions together to create an object. The __init__,  __str__, __repr__,..., etc. method which defines the class and initialize the class. The subclass which I found is very convenient. This is also called class inheritance as it inherit the characteristics from a preexisted class and add additional functions to make the 'object' behave in a certain way. The subclass shows the characteristics of 'lazy geeks' or smart geeks perfectly. 

Recursion also plays an important role in object-oriented programming  Recursion saves a lot of work for computer scientists, it's a function calls itself. We did some exercises on input and output numbers using recursion. The very basic example nested list illustrated how recursion works in a simple and elegant way. I feel that recursion is a very interesting and convenient tool compare with iteration. However, tracing recursion was a bit confusing. We must trace the function calls in order, just like trying to understand how a computer thinks when calling recursion, step by step. For example:

  1. Trace nd([5, [[1, [2, 3], [4]]]]) 
         nd([5, [[1, [2, 3], [4]]]])
         --> 1 + max([nd(x) for x in [5, [[1, [2, 3], [4]]], ’ox’]])
         --> 1 + max([0, 3, 0]) --> 1 + 3 --> 4
    
This was an example we did in lab. The funny thing is I always have the impulsion to just sum up all the integers in the bracket. It's kind of ridiculous, but I think it's because I'm not used to recursive functions and concatenate the sub calls of the function itself. Recursive thinking might help. 

Later in the course, we also studied 'Trees', which combines the knowledge we learned from 'class' and recursion. Trees are a set of nodes with edges between. It's special characteristics which only have one path from the node to the root and no cycles make trees to represent inheritance hierarchical relationships in programming. It might be difficult at first when we try to get a certain node in lab exercises, its easy to mess up and went to a wrong path. However, once we get familiar with how the relationships in trees works everything became smooth.