Thursday, April 2, 2015

Last Impressions

Last evening, we had our last lecture for CSC148. This semester has been a mixture of anxiety and stress for me, but now I actually feel a bit wistful to it. I will certainly remember the days I spent at Bahen Center doing my assignments and figuring out what is wrong with my code for a thousand times. Sure, there were frustrating moments; but the joy, which came from running the code successfully after persistent efforts, was a priceless treasure. 

One of my favourite quote from Blade Runner is, "All those moments will be lost in time, like tears in rain." I know, some day these moments will become meaningless fragments; but for now, they are my witnesses and my milestones. They reminds me the efforts I made for this course and my passion for it.

Let me just say goodbye to CSC148 one last time.




Sunday, March 29, 2015

Revisit

The prompt of this week is to revisit one of my earlier slogs and to see whether I still agree with it or not. Midterm Summary is one of my favourite slog, because it genuinely reflects my state of mind at that time, and I would like to see how my thought has changed or remained the same.

In Midterm Summary, I mention the differences between CSC108 and CSC148. When I talk with my friends, almost everyone agrees that the materials of CSC148 are harder; we have been intimidated, but we generally are able to handle them after continuous practices. After all, learning is a series of systematical progresses.

I also talk about how great Prof. Heap is, and now I rate him even better. He is literally the best. The strike has been distressing for a lot of us, and Prof. Heap helps us to get it through. My friends and I all think that he really cares about us. 

At the end of Midterm Summary, I complain about my stressful timetable. Because of the strike, lots of labs and tutorials have been canceled, and I have more free time in return. I am quite good at learning on my own, so it is actually beneficial for me in some ways. This semester is about to end soon, and with all of our TA’s back, I believe everything will finish without any trouble.


Monday, March 23, 2015

Week 9: Midterm 2

We had the second midterm test on Wednesday of week 9, and it lasted an hour. Prof. Heap had more office hours than usual to answer our questions before the test, since the TA's were on strike. He was extremely helpful, and I admired the fact that he kept patient and kind to us even though he was very tired. 

The test was quite related to the materials covered in the lectures, so I would say it's a fair test. We were allowed to bring a aid sheet with us, same as the first midterm. As a matter of fact, I found that preparing a aid sheet helped me mastering study materials, since I needed to fully understand them in order to plan out the content of my aid sheet. 

After the test, we had an hour of lecture, which was mainly about binary search tree (BST) functions. Prof. Heap went through the implementing process of function insert and function delete with us. He asked questions and drew graphs so that we could understand how these two functions work under different circumstances. It was frustrating to have a lecture right after the test, but we made it.



Sunday, March 15, 2015

Week 8: Assignment 2

Assignment 2 was ... confusing. Especially for the strategy minimax. It took me several hours to argue with my partner about how it really works, with pages of doodles and nonsense, and ended up even more confused and frustrated than before. We could not go asking for TA's help, because of their prolonged strike, which has no sign of ending at this point when I am writing this slog. Luckily, after hours of waiting in the line, I finally got the chance to discuss with Prof. Heap about my confusion, and he easily solved the problem in less than a minute.

The main point of minimax is to keep score for both players to determine how good or how bad their positions are. As described in the guideline file of assignment 2, the score system is:

If the game is over, A's score is:
1 if A wins;
-1 if A loses;
0 if it's a tie.
B's score is -1 times A's score, since this is a zero-sum game: what's good for A is bad for B.

Suppose the game is not over, and the current player is A. Then A's score is:
1, if at least one A's legal moves leads to a new position where A's score is 1 (or  B's score is -1, since B is the current player in the new position);
-1, if every legal move for A leads to a position where A's score is -1 (or B's score is 1, since B is the current player in the new position);
0, if at least one of A's legal moves leads to a score of 0, but none lead to a score of 1. 

I could not understand how it works in a situation that both A and B have a legal move that leads to a new position where their score is 1. Wouldn't both of their scores be 1 in the above situation? But clearly someone's score should be -1. My partner tried to convince me that I should only look at one player's score and ignore the other, but I doubted that's the case.

In the end, Prof. Heap helped me to get out of this paradox. He told me that it's about who is the current player in the situation. If A is the current player, than A will choose a move that leads A's score to be 1, and A will never choose a move that leads B's score to be 1. No matter how many moves there are and no matter how many new positions these moves could lead to, the only one matters is the one that is the best for the current player, and that position determines the scores for both players.

After Prof. Heap's simple and effective explanation, the whole paradox was no longer confusing. I was so happy and relieved. It didn't take us much time to work out the code as long as we understood the rationale behind it. 



Sunday, March 8, 2015

Week 7: Binary Tree

In week 7, we learned the data structure of binary tree. Basically, it is the same with tree data structure, except that a binary tree has at most two children, which are referred to as the left child and the right child. While visiting other students' slogs, I noticed some students posted code on their slogs, and I found it made the abstract description easy to understand. Therefore, here are some binary tree code:


class BTNode:
    '''Binary Tree node.'''

    def __init__(self, data, left=None, right=None):
        ''' (BTNode, object, BTNode, BTNode) -> NoneType

        Create BTNode (self) with data and children left and right.
        '''
        self.data, self.left, self.right = data, left, right

Professor Heap led us to implement a function for the BTNode class, which is called evaluate, through exercise. Evaluate makes calculation based on the data of BTNode using recursion. I found it easier than writing functions for tree, or maybe I am just getting used to it. 

def evaluate(b):
    ''' (BTNode) -> float

    Evaluate the expression rooted at b.  If b is a leaf,
    return its float data.  Otherwise, evaluate b.left and
    b.right and combine them with b.data.

    Assume:  -- b is a non-empty binary tree
             -- interior nodes contain data in {'+', '-', '*', '/'}
             -- interior nodes always have two children
             -- leaves contain float data

    >>> b = BTNode(3.0)
    >>> evaluate(b)
    3.0
    >>> b = BTNode('*', BTNode(3.0), BTNode(4.0))
    >>> evaluate(b)
    12.0
    '''
    if b.left is None and b.right is None:
        return b.data
    else:
        return eval(str(evaluate(b.left)) +
                    b.data +
                    str(evaluate(b.right)))

We also learned binary search tree (BST), which is a special kind of binary tree. It needs to fulfill the restriction that self.left.data < self.data < self.right.data. We then implemented more functions about binary tree and BST in the lab. 

Moreover, I started assignment 2 in week 7. I found an awesome teammate, and he made the whole process joyful and relaxed, even though this assignment is hard in some way. I will write in more details next week.


Sunday, March 1, 2015

Midterm Summary

At first, let me indicate clearly: I would like to choose my summary of OOP to be graded. 

Then I have to talk about something else to get this slog done. Since we are right on the mid-point of this semester, it is a good time to sum up what I have learned during the first half of this semester, and my thoughts on these materials.

Compared with CSC108, CSC148 takes us to the next stage of python. CSC108 was more about how to use the built-in functions of python, such as string, list, and dictionary. On the other hand, CSC148 is leading us to build our own programs using python by implementing classes and subclasses. We also learned complicated programming method such as recursion. Step by step, we are on the exciting way of becoming a mature programmer. 

Also, I love Professor Heap's style of teaching. I am surprised that he can call many of us by name, since this is such a large class. He has designated a large proportion of the course for interactive activities, such as making students to demonstrate how the binary search tree works using cards with number. I enjoy these activities, and I think they help me to understand the course materials better.

To be honest, this semester is tough for me because that I enrolled in six courses. My timetable is full, and as much as I want to, I cannot spend a sufficient amount of time on CSC148. Nevertheless, I managed to master all the study materials, and got an excellent mark on the first midterm test (98%). This is truly remarkable, and I am very proud of myself. Hopefully, my time-manage skills will help me to walk through the remaining half of the semester as well.

ps. I am already missing the reading break!






Tuesday, February 17, 2015

Object-Oriented Programming

This week's prompt is a bit tough to me, since I don't know much about programming languages. Actually, python is the only programming language that I am familiar with, therefore I could not tell the differences between python and other programming languages that are not object-oriented. Nevertheless, based on materials from CSC108 and CSC148, I could still try to summarize concepts that I learned by using python.

One significant characteristic of object-oriented programming is that, as its self-explanatory name show, it let object serve as the basic unit of program. Attributes and methods are restored in objects. Therefore, each object is able to accept and process data. In the lectures of CSC148, I learned about class and subclass. They are the blueprints of objects. Class and Subclass give objects basic attributes and define objects abstractly. In lectures and labs, we have created a number of classes and subclasses, each of them builds different objects to fulfill its assigned functional responsibility.

Moreover, objects can interplay mutually. In the lecture of week 6, Professor Heap implemented a data structure, called tree, using class. He demonstrated how each tree could have other trees as its children. It suggests that objects can interact with each other in different ways. They are not necessarily at the same level. This concept really attracts my interest, and I would love to learn more about how objects are connected with each other.

Object-oriented programming is a rather big topic, and there must be concepts that I am not aware of. I hope next lectures could further expand and deepen my understanding of OOP.




Sunday, February 8, 2015

Tracing Recursion

In the lecture of week 4, we learned the concept of recursion, and how to trace a recursion function. In computer science, recursion is the method of using a function in the definition of the function itself. It is different from typical thinking pattern of human beings. For example, to count non-list elements of a list containing sub-lists, computers would have to work from a list to its sub-lists to sub-lists of sub-lists and so on, while human would count whenever we see a non-list element, no matter which layer of sub-list this element is in.

Tracing recursion functions helps us to understand how they behave. Professor Heap demonstrated how to trace a recursion function line by line. We should try to think as computers when tracing recursion functions, from one step to the next, even though we have the ability of jumping to the conclusion. At first, I was not used to it, and I had to force myself to follow the lines. However, after practicing, I figured out the trick. Instead of looking at the whole jigsaw at once, I should start with the first piece of puzzle and move forward, following orders from recursion functions. With this idea in mind, the whole process was no longer confusing.

After I mastered the skill of tracing recursion functions, the logic behind these functions became clearer. In lab #3, we were asked to write a single function using recursion, and it didn’t take me much time. I am looking forward to writing more recursion functions.



Sunday, February 1, 2015

First Impressions

During the first weeks, I finished my first assignment. It was about creating a simple game using python. At the first glance it was overwhelming, and I honestly thought about whether I should drop this course to escape from it. It was different from those assignments I used to deal with in CSC108; in the good old days, the instructor would give specific details and instructions about every single function, and all I had to do is only to follow these instructions. In this assignment from CSC148, the instructor only provided general and abstract guideline, and I had to come up with my own design of the functions.

At first, I literally had no clue where to start this assignment. I just forced myself to write something. Once I got involved, a vague imagine of next steps started to form in my brain; and I followed it. It was a messy style of working, and I paid my price for it - I had to edit my whole file after I finished it. Nevertheless, my game did work successfully, allowing my friends to play without any error.

Looking back, I would say this assignment was a good challenge for me to start programming on my own. After all, I can't rely on the instructor and TAs for my life; someday I would have to work independently. There is still a long way till I could finally master programming, but I have the confidence to walk through.

Saturday, January 24, 2015

Why Geeks Should Write?

I personally always believe that writing is a vital skill for every person, regardless of whether you are a geek or not. One of my favourite quote about writing is "We write to taste life twice, in the moment and in retrospect", from Anaïs Nin, a french writer. I think it penetrates the essence of writing.

One huge benefit of writing is that it helps us to communicate with the world. Imagine you are programming, and your code is extremely good. However, it means nothing to people who don't understand programming language. You need to introduce your work to them using ordinary language, helping them to realize what amazing functions your code can accomplish. Now, this is the stage owned by good writers. With several lines, they can convey the idea behind their code to the client, thus making it more user-friendly. Good communication is the key of being likeable.

Moreover, writing helps us to get our thoughts into shape. Keeping a diary is one of my habits, which I found useful to organize my emotion and to make important decisions. With writing, I can sort out information, analyze relationship between ideas, and logically draw my judgement and conclusion. Some people may think writing is all about sensibility; but in my opinion, it is more about sense.