Friday, 27 February 2015
Saturday, 14 February 2015
Week #6: Object-Oriented Programming (OOP)
What is Object-Oriented Programming?
Object-Oriented Programming is type of programming that consists of objects that are manipulated to satisfy the needs of the program.
Object-Oriented Programming is what this course has been mainly focusing on. So far we have learned about how to create classes and methods including special methods such as __init__, __repr__, __str__, __eq__. To create an object you create an instance of a class.
We also learned about an important OOP concept called inheritance. Inheritance is when a class inherits code or behaviour from another class. The class inheriting the code is called the subclass or child class and the other is called the parent class. Inheritance was a large component of Assignment 1. In the assignment we created two main parent classes for a general game state and a general strategy. These parent classes had subclasses of a state of a specific game called Subtract Square and a specific strategy that chooses randomly what move the computer makes.
Overall these are some of the concepts of Object-Oriented Programming that we have covered so far, and I'm looking forward to what we learn next!
Object-Oriented Programming is what this course has been mainly focusing on. So far we have learned about how to create classes and methods including special methods such as __init__, __repr__, __str__, __eq__. To create an object you create an instance of a class.
We also learned about an important OOP concept called inheritance. Inheritance is when a class inherits code or behaviour from another class. The class inheriting the code is called the subclass or child class and the other is called the parent class. Inheritance was a large component of Assignment 1. In the assignment we created two main parent classes for a general game state and a general strategy. These parent classes had subclasses of a state of a specific game called Subtract Square and a specific strategy that chooses randomly what move the computer makes.
Overall these are some of the concepts of Object-Oriented Programming that we have covered so far, and I'm looking forward to what we learn next!
Sunday, 8 February 2015
Week #5: Recursion
A recursive function is a function that calls itself. These functions are useful in programming as they provide an optimized method for implementing repetition in a program.
This recursive function has an incomplete docstring. Therefore you have to carefully analyze the code given to figure what it does and you can test it with simple examples to confirm your understanding. When tracing a recursive function you must trace the function calls in order. You can replace return with --> and if you have already traced a similar call you can just plug in the result. For the example above we can trace nd('ox'), nd([2,3]), and nd([2, [3, 8], 5, [2, 6], 7]):
(from lab #3 sheet)
nd(’ox’)
--> 0 # ’ox’ is a non-list
nd([2,3])
--> 1 + max([nd(x) for x in [2, 3, 'ox']])
--> 1 + max([0, 0, 0]) #already traced nd of non-list
--> 1 + 0
--> 1
nd([2, [3, 8], 5, [2, 6], 7])
--> 1 + max([nd(x) for x in [2, [3, 8], 5, [2, 6], 7, 'ox']])
--> 1 + max([0, 1, 0, 1, 0, 0]) #already traced nd of a non-list and a list consisting of non-lists
--> 1 + 1
--> 2
In Lab #3 we practiced tracing recursive functions involving nested lists. Here is an example given in the lab:
def nd(L):
’’’(list or non-list) -> int
’’’
if isinstance(L, list):
return 1 + max([nd(x) for x in (L + [’ox’])])
else: # L is a non-list
return 0This recursive function has an incomplete docstring. Therefore you have to carefully analyze the code given to figure what it does and you can test it with simple examples to confirm your understanding. When tracing a recursive function you must trace the function calls in order. You can replace return with --> and if you have already traced a similar call you can just plug in the result. For the example above we can trace nd('ox'), nd([2,3]), and nd([2, [3, 8], 5, [2, 6], 7]):
(from lab #3 sheet)
nd(’ox’)
--> 0 # ’ox’ is a non-list
nd([2,3])
--> 1 + max([nd(x) for x in [2, 3, 'ox']])
--> 1 + max([0, 0, 0]) #already traced nd of non-list
--> 1 + 0
--> 1
nd([2, [3, 8], 5, [2, 6], 7])
--> 1 + max([nd(x) for x in [2, [3, 8], 5, [2, 6], 7, 'ox']])
--> 1 + max([0, 1, 0, 1, 0, 0]) #already traced nd of a non-list and a list consisting of non-lists
--> 1 + 1
--> 2
Saturday, 31 January 2015
Week #4: The First Few Weeks....
The semester started with some review of main concepts we learned in CSC108. We then progressed on to more complicated things such as classes and subclasses interactions. Our very first assignment was based mainly on this.
I struggled quite a bit with this assignment. One main obstacle that I struggled with was organizing all the classes and subclasses. I had absolutely no clue where to start. Initially I found it quite confusing to keep track of all the variables and the functions. However with the help of several posts on piazza, many of my questions where answered. As the completion of the program progressed, things made more sense, but of course there are always errors. However with patience and the help of TA's, the assignment finally came together.
There are two main things i've learned from the past couple of weeks:
1. With this course there are several resources from which you can get help with your programming. These include the Computer Science Help Centre, Tutorials and piazza. It is definitely worth your time to use them.
2. As it might be obvious from my description of how this assignment went, I was very frustrated. This is not a sign of a good programmer.
Primarily I need to manage my time better and definitely improve on organizing my process for completing an assignment. Another aspect I need to improve on is debugging. Debugging is a very useful skill to have in programming, if you know how to efficiently do it, you can save a lot of time and effort.
Overall, although some of these weeks have been stressful, I did take away an important lesson that will help me in the future.
Sunday, 25 January 2015
Week #3: Why Geeks Need to Know How to Write.....
Communication is arguably one of the most important life skills to possess. Communication is not always verbal, therefore it is extremely useful to be able to communicate at the same level through writing as you can verbally in this day and age. Communicating verbally and through writing are dependent on one another.
Geeks are often described to be intelligent people that are glued to a computer or merely focused on scientific and mathematical equations. They are portrayed as if they live in a world of their own where they create and accomplish incredible things. However in order for them to be successful in whatever field they are passionate about, they need to be able to properly communicate their thoughts, ideas, and creations with everyone else. Geeks are perceived as preferring to focus on computers instead of people and this missing social aspect can be a great flaw in character.
Geeks are often described to be intelligent people that are glued to a computer or merely focused on scientific and mathematical equations. They are portrayed as if they live in a world of their own where they create and accomplish incredible things. However in order for them to be successful in whatever field they are passionate about, they need to be able to properly communicate their thoughts, ideas, and creations with everyone else. Geeks are perceived as preferring to focus on computers instead of people and this missing social aspect can be a great flaw in character.
Subscribe to:
Posts (Atom)