Saturday, 4 April 2015

Hello, Goodbye (Final Impressions)



Finals are here!
Hence it is time to conclude my journey in CSC148. 
With no doubt, this course took my programming skills to a new height and garnered me interest in furthering my studies in computer science. The assignments were very challenging(especially A2), but intriguing! 

Looking back, there were quite some hurdles and frustrations. 
As programmers say, one's program can never be perfect. There is always some way in improving it, whether it be representation or efficiency. 

Overall, one of my biggest hurdles in CSC148 was the concept of recursion. 

When recursion was first introduced, I was overtaken by its beauty, as well as intimidated by its seemingly precarious and difficult nature(as a poorly written one can create infinite loops which will burn through your computer). It is such a magical function,as it is powerful enough to put near infinite steps into something very succinct. 
At first, I found writing recursive functions(especially complex recursive functions) very difficult. Writing them requires a mindset or thinking of recursion. This ability may be enhanced with practice, but it also depends on the creative intuition. 
When we used recursion subsequently in binary search trees and linked lists, things became more difficult. 
In the lab for linked lists, it often took me more than 2 runs in the shell to get a function right. However, as my classmate has said in week 11 post, practice will always make one better! :) (http://whydopigsquack.blogspot.ca/2015/03/week-11.html)
From reading other classmates' blogs, I see that most people list their favourite posts that they have come across during SLOG writing. Hence I will do this, too. 

1. As I have previously stated in my OOP post, I really like WhyDoPigsQuack's post on OOP concepts.  (http://whydopigsquack.blogspot.ca/2015/02/oop-there-it-is-oop-there-it-is.html). I think this classmate here wrote a very thorough summary of OOP class design. 

2. In general, I enjoy reading CL's blog posts(http://allthemontypythonjokes.blogspot.ca/). Her posts are always quite entertaining and anecdotal. I see a mix of personal progression, technical knowledge and funny images, which is great! 

3. Throughout the course, I often visited calvincsc148slog.blogspot.ca. I believe the blogger writes with very concise and clear language, which is perfect for a computer programmer. I, on the other hand, tend to suffer from the "many words" syndrome because I have been enrolled in a rhetorical writing course this year. 
Specifically speaking, I really like his blogpost on revisiting week 3 (http://calvincsc148slog.blogspot.ca/2015/03/revisiting-week-3-slog-of-why-geeks.html). It offers new insight about why geeks should write. For instance, I have never thought of the problem writing and concise comments before. Complex programs require a planning process presented on paper. However, the format and the specifics must be constructed in a way that is also understandable by other programmers on the team. I have experienced myself the great difficulty in reading friends ' comments in programs sometimes. For A2, my head hurt so much after reading my friend's code(even with comments). 

Anyhow, I enjoyed learning from CSC148 this year. However, I must say that the weeks gone without TA help were horrendous. I usually gain deeper understanding of concepts during tutorials. However, my learning process was compromised during those weeks. 

Thank you for reading my last blog on CSC148!
The FlyingFish must finally proceed to the final exams!



-------------------------------------FLYINGFISH----------------------EXOCOETIDAEE-----------------------

Friday, 3 April 2015

Revisit of OOP Concepts




 I will look back at my Summary of OOP Concepts post.

I believe I have covered objects and inheritance well. If there is anything to be added, then it should be a brief note distinguishing functions and methods.

Check out the code I briefly wrote:

class Happy:
    ''' insert description '''
    def __init__(self):
       
        self.things_that_make_me_happy = ['coconuts','creamcheese','tea']
       
    def delete(self, thing):
       
        if thing in self.things_that_make_me_happy:
            self.things_that_make_me_happy.remove(thing)
        else:
            return "This thing did not make you happy!"
       

def delete(lst, thing):
   
    if thing in lst:
        lst.remove(thing)
    else:
        return " item not in list."
   

In the shell:

>>> d = Happy()
>>> d.delete('tea')
>>> d.things_that_make_me_happy
['coconuts', 'creamcheese']
>>> delete(d.things_that_make_me_happy, 'coconuts')
>>> d.things_that_make_me_happy
['creamcheese']


So is there really a difference between the functionality of delete and the delete method in Happy?
Not really.
The only difference(quite negligible here) is that the delete method must be activated(used) in objects, not just on any list that we randomly create.
In other words, the OBJECT has to exist for the utilization of the method to occur.
However, function delete is global. The lst does not have to be the list from the object Happy.

A further note:

After a semester of programming using OOP concepts, I must emphasize again that OOP is a very efficient way of programming! As a student, my mind set has shifted from procedural to objected-oriented. Whenever I start to program, I think about how I can organize the features, key aspects, and data(if any) in objects for purpose of efficiency. Combined with recursion, as we have seen in A2 and A3, we are able to write larger programs with less number of lines than we have used in 108.


---------------------------EXOCOETIDAEE-------------------------------


Tuesday, 31 March 2015

Week 9: Impressions



My biggest frustration occurred when I ran the minimax unit test. Clearly, errors were returned, which wiped out my dignity as a programming student. Ha, ha, ha...


In A2, the minimax we wrote only worked for Subtract the Square, but not with Tippy.
I suspected that something was wrong with TippyGameState. Indeed, it was! 

I realized the mistake after debugging from GameView (the overall program for running the game):
       while not self.state.over:
            if self.state.next_player == 'p1':
                m = self.state.get_move()
                while not m in self.state.possible_next_moves:
                    # The move was illegal.
                    print('Illegal move: {}\nPlease try again.\n'.format(m))
                    print(self.state.instructions)
                    print(self.state)
                    m = self.state.get_move()
                print('You choose: {}'.format(m))
            else:
                # The computer makes a move.
                m = self.strategy.suggest_move(self.state)
                print(m)
                print('The computer chooses: {}'.format(m))
            self.state = self.state.apply_move(m)
            print('New game state: ', str(self.state))
            print()

When the game is played, the first round would work. Self.possible_next_moves would return a list of all the possible moves available initially in the game.
However, the problem occurs in apply_move, that it does not properly modify self.possible_next_moves. 
I tried to modify possible_next_moves every time apply_move is called. However, for some reason, possible_next_moves remain constant. 

Basically, the mistake made was keeping a list of possible moves as a variable within the object. Hence I'm mutating it as game states change. This is a very bad idea because the default when create in the object is the original game state( with all possible moves in the initial state). 

UPDATE: I think another mistake I made was not reading the code provided by the instructors first in Subtract the Square. In the exemplary file, possible_next_moves is actually a method! Ooops... In the future, I must take more precaution!

-----------------------------------------------EXOCOETIDAEE---I--AM--A--LINE----------------------------





Sunday, 15 March 2015

Reflections on Last Week



Sorry, readers! I put off this post off for a bit...
The force of procrastination induced me to stay in my bed...

What happened this week?

Well, term test 2 happened to me... 
How did it go?

                                                                      Je ne sais pas 
Say nothing
Think of nothing
               Ignorance is bliss    
          



I have lost my magical ball of grade prediction after completing 100000 midterms and 1000 quizzes since starting school. 
Hence I will write about anything but speculation on my test scores. 

Back on topic: course material
The most interesting concept we have learned so far is the binary tree, or specifically speaking, the binary search tree(BST). 

A binary search tree is an ordered version of the regular binary tree.
Its left child's value is smaller than the node's value, and the right child's value is greater than the node's value. 


I find this structure very intriguing! Every time I look at a BST, I think of holding the parent node and having other nodes dangling on the sides. Sometimes, the BST also reminds me of a christmas tree!


Overall, I think the implementations of functions that traverse through the BST are very challenging. 
Here is an example from the lab:
def list_between(node, start, end):
    ''' (BTNode, object, object) -> list

    Return a Python list of all values in the binary search tree
    rooted at node that are between start and end (inclusive).

    >>> b = BTNode(8)
    >>> b = insert(b, 4)
    >>> b = insert(b, 2)
    >>> b = insert(b, 6)
    >>> b = insert(b, 12)
    >>> b = insert(b, 14)
    >>> b = insert(b, 10)
    >>> list_between(None, 0, 15)
    []
    >>> list_between(b, 2, 3)
    [2]
    >>> L = list_between(b, 3, 11)
    >>> L.sort()
    >>> L
    [4, 6, 8, 10]
    '''
    if node is None:
        return []
    else:
        if is_leaf(node):
            return [node.data] if (start <= node.data <= end) else [] 
        else:
            if start <= node.data <= end:
                d = [node.data] 
            else:
                d = []
            left_list = node.left
            right_list = node.right
            return list_between(left_list, start,end) + list_between(right_list,start,end) + d

Functions involving more complex recursion, like the one above , really bring our progress one step further. Just earlier on in the semester, we were still implementing very simple recursive functions. 
However, as of now, I still find it a bit intimidating to implement complex recursive functions(especially on tests, when the code cannot be tested). To increase my confidence on recursive functions, more practice will do. I will have to do the labs again! 

Impressions on course logistics and student support:

As finals and A3 deadline approach in the vicinity, the TAs aren't helping us with the strike. We haven't had formal labs for more than two weeks. As a student in a course with tight deadlines, namely CSC148, I feel very nervous and anxious. 

Office hours are immensely helpful; however, time is a big issue because I often have other classes to attend during office hours. 

Let me end this blog post with optimism:

Despite all the turmoil we students have experienced, the end of the school year is still coming! May we find happiness even in the most stressful times! Let's hope for the best and keep working hard! 

After all, practice makes perfect. 

-----------------------------EXOCOETIDAEE.BLOGSPOT.CA-------------------------------------------------

Saturday, 7 March 2015

Impressions, Impressions, Impressions


So, you asked for my impression on the past week?



T'is another torturous week
The Tempest has arrived
Day and Night
Night and Day
Fingers dance on the keyboard
while elves with crooked wings battle on WING
Brains on flames for minimax 
exhaustion at maximum
Tic, tic, tic 
Time is slipping, slipping
Away with our self-confidence 
As the hand hits 12
When the horses turn into rats
When our program is uploaded to Markus
All is done
Nothing could be done
Do not weep for thy failures
Prepare for the next round 



Indeed, Assignment 2 was very challenging. In the end, our minimax works with Subtract the Square game, but is incompatible(somehow) with the TippyGameState after one round. 
Even though the deadline is long past, I will continue my search for bugs that impeded the program from running correctly. 
For this assignment, none of our group members sought help from instructors. In the future, I would like to manage time in a more efficient manner and make time for consulting. 


Saturday, 14 February 2015

Summary of OOP Concepts

Well, well, well...
How coincidental is that I am writing on the first day of reading week and the evening of Valentine's Day? 

#Sad life of a (U of T)student...

Since it's such a special day, let me have some fun before I start rambling about objected oriented programming!  

After surviving the past few weeks, I just feel so obliged to share this with you:


Okay, back on topic...

Summary of OOP Concepts

A world of classes, objects(data types), interface, and abstract data types. 

To be honest, I am not the best at summarizing things...
I prefer to write essays instead.
 :) But I will try my best here. 

OOP, also known as objected oriented programming, is a programming paradigm based on objects(bundles of bits) and data rather than logic. 

Back in 108, we mainly exercised in procedural programming, where we focus on writing functions(procedures on data). 

OOP opened the gates to a vast new world, one that is full of complexity and data. The essence of OOP lies in higher level thinking about the organization and structure of data. The creation of classes allow the creation of many objects and a useful interface; we can thus create distinct entities that have their own functionality and data. 

In class, we have mostly emphasized on class design and inheritance. 

Class design can be a nebulous concept because there are so many ways to design a class! You can choose to only have parameter self in the constructor and have data storage internalized, and have methods for manipulation; on the other hand, you can choose to have different parameters for user input. 

But I believe it is always useful to ask yourself a couple of questions before you write a class:

1. What kind of data are you processing? 
2. What kind of objects would you want? Look for key words!
3. What attributes do you want for your objects? For example, a turtle class would want to have a tail as its attribute. 

Inheritance is what it suggest; it is the idea of having a child class "inheriting" attributes from the parent class. 
To illustrate its connotation in the English language, check out the classes I have here:

class Coco:
''' Coco is the parent of Joan'''
    def __init__(self):
        self.hair_colour = 'blue'
        self.eye = 'black'
        self.wings = 'green'

class Joan(Coco):
''' Joan is the child of Coco'''
    def __init__(self):
        Coco.__init__(self)
        self.wings = 'orange'   # I am a defiant DNA. 

Basically, Joan inherits all attributes of Coco(blue hair, black eyes) but may not be identical (have orange wings) as Coco. 

To further illustrate the utility of OOP in general and summarize it, let us take a look at another real world example. 

Mr.Potter recently opened a restaurant on Bay Street; he then wonders how he should process orders of his numerous customers without abusing his employees' memory capacity. 

So Mr.Potter can construct a class named OrderSystem and a class Order. OrderSystem can have attributes such as active_orders, implemented_orders, total_customers, and various methods. Class Order can have more specific attributes such as customer_name, table_number, time_of_order, and total_price. With each new order, a new object Order is created and stores the information of that specific table. 

i.e.
class OrderSystem:
    ''' A data system that stores information of orders.'''
    
    def __init__(self):
        
        self.active_orders = []
        self.implemented_orders = []
        total_customers = 0 
        
    def add_customer(self, name):
    
        pass
        
class Order(OrderSystem):
    ''' Class for specific order, inherits from OrderSystem.'''
    def __init__(self, customer_name, table_number, time_of_order):
        
        OrderSystem.__init__(self)
        self.customer_name = customer_name
        self.table = table_number
        self.time_of_order = [time_of_order]
        self.total_price = 0
    
    def add_dish(self, dish, order_time):
    
        pass

Personally, I think OOP is a very valuable, intriguing concept that is very practical. When solving problems in the real world, we often face a large pool of data(whether it be a list of patients, data tables of weather patterns or bank account data). OOP in turn allow us to store and process this data in a fairly organized manner. 

Also, as I was walking around my classmates' blogs, I found this classmate of mine, (http://whydopigsquack.blogspot.ca/) wrote a very nice summary of OOP concepts. Hence do keep in mind that if you do not find mine most helpful, you can always take a look there.  :)
You can also consult http://openbookproject.net/thinkcs/python/english3e/index.html , which I draw some of my information from. 

---------------------------------------FLYINGFISH's FINISH LINE--------------------------------------------
Thank you for reading! If you are nice, please comment below so I know you are there! :)


Saturday, 7 February 2015

['R',['E'],['CU'],'R',['SION']]


RECURSION
  RECURSION
       RECURSION
           RECURSION
              Aren't I bored? 


How we met recursion:

















"The magic of recursion lies in its ability to perform countless computations with just a few statements."
                                                              - Flying Fish (CSC148)

When we were first introduced to the concept of recursion through readings(the one about fractals), I, along with some classmates, found it fairly confusing. 

However, I managed to grasp the idea with the help of the fourth lab and more recently, the fifth. 

Instructors have defined a recursive function as one that is able to call itself over and over again. 

Though if I am to summarize to my best ability in form of analogy, recursion is similar to opening one of those layered gift boxes, which I used in middle school for 'dramatic effects' at my friends' Birthday parties. 

Here's the closest picture I can find:

# Mine weren't so fancy; and, I usually prefer to have multiple boxes(or small bags) at one level to make sure my friend will not get to the gift too easily.

Until the gift is found, the recursion can keep calling itself(that is, to continue opening boxes).

To put it in code:

def find_gift(L):

    if isinstance(L, gift):   # pretend gift is a type in python, just like list and str.
        return L
    else:
        find_gift(x) for x in L


At first, tracing some functions in lab 4 for nested lists was very confusing. However, I later realized what I was doing wrong after consulting my professor during the office hours. Frankly, I usually over traced and spent lots of time because I did not use the traced results from previous steps.
After learning from my mistakes, I had fun tracing more recursive functions!

In lab 5, I wrote list_queue and did tracing on paper.

def list_queue(lst, queue):
     

    for element in lst:
        queue.enqueue(element)
         
    while not queue.is_empty():
        d = queue.dequeue()
        if isinstance(d, list):
            list_queue(d, queue)
        else:        
            print(d)

As I drew things in piles on paper, everything came to sense! 
For instance, a list such as [1,[3,5],[4,[5,6],8],9]


1  ------> print(1)
[3,5]
[4,[5,6],8]
9 --------> print(9)
3---------> print(3)
5 ----------> print(5)
4-----------> print(4)
[5,6]
8-------------->print(8)
5--------------->print(5)
6----------------->print(6)



---------------------------------------FLYINGFISH's FINISH LINE--------------------------------------------
See you next time! (zzzzzZZZzzzzzz)


Saturday, 31 January 2015

My Feelings/Impression (For/On) the first few weeks

---------------------------------------------FLYINGFISH 's START LINE-----------------------------------


Readers,

It is my fault that I did not make known to you the purpose of this blog...

The FlyingFish has been too eager diving into the ocean.

Now that I'm in the air, I have a few seconds to talk about it!

I am currently undertaking a course by the name of Introduction to Computer Science(CSC148). 
This blog(or SLOG) is to record my journey, whether filled with failures or success. 
An important note is, it is highly likely for this blog to continue beyond the timeline of this course, as the author is discovering the joy of blogging.  :) 

Back on Topic: My Feelings about the first few weeks of 148



Well, I am very glad that I get to talk about my own thoughts of the class! 

Coming from 108, I find 148 to be a very different course. In 108, we were fully armed with the tools needed, and all that we need to do is synthesize. From videos to lectures, I seldom find myself lost on the crossroads. Assignments grow in size and difficulty, but I always find them manageable. 

However, to be honest, after the first class in 148, I was engulfed by uncertainty. 
In class, more abstract ideas are discussed, as opposed to how such ideas should be implemented. There are many ways of implementations, but they all belong to that idea. 

For instance, we can use composition to use a class in another, but we can also use inheritance to foster that connection. As to how to structure classes and their relationships, it is up to our judgement.
Sometimes, especially for me, it can be very hard and time consuming to figure out which class should inherit from which and what should the overall structure look like. 

In Assignment 1, I misinterpreted the instructions and ended up having two gameview classes, with my specific gameview implementing the SubtractSquare game. In other words, my main focus was on gameview rather than game state. 

I thought I was doing the right thing, until I discussed more with one of our group mates. Hence it resulted in hours of chaos(not the chaos from chaos theory) and frenzy to fix the code. In the end, we managed to complete our game state and reform other classes. 

While working on the assignment, I experimented with "mutual inheritance" between two classes. 
For instance, here is an arbitrary example:

Module HappyFace.py:

from SadFace import SadFace

class HappyFace(SadFace):
    ''' A confused face.'''
    def __init__(self):
        SadFace.__init__(self)

Module SadFace.py:

from HappyFace import HappyFace

class SadFace(HappyFace):
    ''' blah blah blah'''

    def __init__(self):
        HappyFace.__init__(self)

Unfortunately, the running of the programs resulted in errors. Hence I conclude "mutual" inheritance is not allowed. But wouldn't it be cool(and perhaps useful) to have lots of classes that inherit from each other?

------------------------------------------------------------------------------------------------------------------------
Overall, I think 148 is a very challenging class. To resolve my confusions, I have to dig more into the readings and watch more videos from previous sessions!

---------------------------------------FLYINGFISH's FINISH LINE--------------------------------------------
See you next time!


EXOCOETIDAEE.BLOGSPOT.COM

Thursday, 22 January 2015

Why Geeks Should Write

---------------------------------------------FLYINGFISH 's START LINE-----------------------------------


Now, allow me to reform this sentence.

"Why should geeks write?"



Since English is an ambiguous language, I always like to define key terms before proceeding further. 

After a search, I found some rather interesting results:




What was your reaction after reading Merriam Webster's first definition?

You can post yours later in the comment area, but here's mine:


It should be most prudent to keep it simple...

For this blog post, a geek will be defined as a computer science enthusiast...

Back on topic: Why Should Geeks Write?
The answer can be astonishingly simple. Geeks are people, and communication between people is key to productivity and happiness in life. 

Geeks can make a difference in this world with their expertise and creativity. However, this possibility must be based on mutual understanding(most efficiently being presented in writing). Innovators must understand the needs of the population; the population must understand the geeks' plans, in order to appreciate the convenience and beauty of the innovation. 
After all, technology is useless if no one uses it. 
Another very important note is that good writing skills would benefit cooperations. Unsurprisingly, different geeks think differently. The different ideas may engender a very creative program, yet they are also capable of causing a ruckus if there exists miscommunication. 
For instance, I have never enjoyed reading another's code because everyone has different logic and coding styles. Now, imagine having a huge program in front of you with no docstring. 

                                      Ha ha ha...

Surely,the ability to write will benefit all the geeks out there! Writing an explanation for a program not only allows oneself to understand his or her code clearly, but also provides a platform of understanding for other viewers. Because others can understand the code, they can thus provide feedback or criticism that can only ameliorate the product. 



That's it for today! Thanks for reading!
This is my inaugural blog post :)
---------------------------------------FLYINGFISH's FINISH LINE--------------------------------------------

EXOCOETIDAEE.BLOGSPOT.COM