Sunday, February 15, 2015

week6: my impression of week5 and week6 My summary of Object-Oriented Programming concepts

In this week's slog, I will talk about my impression on week5 and week6 and give a summary of objective-oriented programming concepts.



Last week we talked about stack and queue and a little more about recursion. Stack and queue are containers of data. We can add elements to the end of the stack and delete the element in the end. On the contrary, we can add elements to the start of the queue and delete the element in the end. It just likes the model of lineup at a coffee shop or vending machine.


Queue and stack can be complicated, such as [1,[2,3],[[4,5,6],7]].
It is easy for us to get lost when we trace it. And the method which we use to deal with queue and stack is recursion.

When it comes to trace recursion. To be honest, I don't like it because it can be complicated. For example, I got lost when I traced the list on last week's lab.
(find the max one of [4 ,5, [6,7,[3,9,0], 6],10]). I asked my TA in help center and I figured out some efficient way to trace: The key thing to trace a recursion is to apply your function step by step. We can't (and not possible) to figure out the final outcome all at once.


This week we talked about Tree. A tree is a container of data with children.
We can put value in a node and edges connect node with nodes.


One of the most important thing which we need to keep in mind is that a tree both has value and many children and children have their own values.


After 6 weeks of studying, we have learned a lot about Object-Oriented Programming. We have learnt how to write a class, how to write a subclass and inherit methods from super class.In this week's slog I want to make a summary of concepts of OOP.

First, some concepts of OOP:

1.objects .it is the basic unit of OOP. Objects can be a function, can be a list of integer.

2.class. Class is a container of methods and data.

3.Subclass. Class can inherit some methods from super class and share some properties.

4.inheritance. subclass can inherit methods from super class.


SO  what is oop?

In my mind, oop is a programming style which focuses on objects and their properties rather than actions. For example, in week three we wrote a class “employee” .Then “employee” was our object then we considered what we need to do with this object in our program. We wanted to record the money which was paid to employees and record the total amount of money which we paid. So we added several methods into the class, such as “record pay”, “total pay”. Then we found that we need more information to complete methods. So we wrote subclasses :“hourly employee”and "weekly employee".  
In a word, oop is programming language model, and we write classes to achieve our goals.

Then, what is the benefits of OOP?

The first thing which comes to my mind is inheritance. As I mentioned above, we wrote subclass and let them inherit methods from super class. It is possible to define lots of subclasses which share some properties of the super class. It is quite efficient.

In a word, OOP is a useful programming method to improve efficiency, and I guess we will continue learning about it through the term.

Sunday, February 8, 2015

week 5: my impressions of tracing recursion from week 4

Week 4 was a really busy week because assignment 1 was due on Thursday.At first, I can't figure out the difference between Game_view and Game_state. After attending Danny's office hour, I got it. Game_state is about the current state of the game, and Game_view is just to start the game.In lecture,we talked about recursion .If we use recursion we can generalize some arithmetic and simplify them.For example, if we want to get the sum of a list of lists without recursion (ie,[1,2,3,[4,5]]) , we should use two "for" loop, and the code could be complicated. If we want to get the sum of a list of lists of lists (ie, [1,[2,[3,4,5]]]), we should write another program using three "for" loop. However using recursion, all these things are the same!In the lab, there is a quite interesting question at the end of the handout, I post the docstring with my own code below which is different from my TA’s answer.




















When it comes to trace a recursion. It is not a very hard problem for me because I learned a bit of recursion in my high school. Prof. Diane represented recursion on the black board carefully and clearly, so I got it.