Sunday, February 15, 2015

Object-Oriented Programming (OOP)

Dear Blog,

Welcome to my first impression of Object Oriented Programming. OOP focuses on objects and methods rather than functions. It looks a lot cleaner and is much easier to read in my opinion. So far, I like object oriented programming.

I think OOP will be very useful in the world of game design. Take our assignments for example: I like that we have created general classes with sub-classes that are specific to different games. I thin OOP is a really useful, and tidy way of programming to successfully access your code and change code without messing everything up.

I agree with the write of this blog http://kurtvcsc165.blogspot.ca/ because one thing I found interesting about OOP in python is the naming of methods in classes. Private and public functions are not new to me but I found it strange that anyone could actually access your private function but putting an underscore before is just a polite way of saying "please don't touch".

I look forward to talking about my next week of class, but for now I'm on reading week. Woo-hoo!

Thanks,
J.M.

Sunday, February 8, 2015

Tracing Recursion

This week I have to write my impressions on tracing recursion from week 4. I found tracing recursion quite simple and straightforward. When tracing recursive functions, I think it is important to start by identifying the base case because that is most likely the easiest case. Then, I would identify the general case. The thing about the general case is, you have to think about it in terms of the base case because after tracing the general case, it will eventually lead you back to the base case.

For example:

def count_elements(L):
    ’’’(list or non-list) -> int
    Return 1 if L is a non-list, or number of non-list elements in
    possibly-nested list L.
    Assume: L is any Python object.
    # examples omitted!
    ’’
    if isinstance(L, list):
        return sum([count_elements(x) for x in L])
    else: # if L is not a list, count it
        return 1

In this example, return 1 when the input is not a list is the base case. The general case is return the sum of the list after it has been passed by count_elements. The general case passes the list into count_elements into there are not more lists within the list. When this happens, we return a 1 using the base case.

That is basically all I have to say about tracing recursion. We also wrote the first midterm of the year for this class this week. I thought it went pretty well. It was pretty much what I expected, decently difficult questions that reflect what you have encountered in lecture and in labs.

Thanks,

J.M.

Sunday, February 1, 2015

First Few Weeks

Dear Blog,

So far CSC148 has been much different than CSC108 but they share some similarities. This class definitely seems like it will be much more challenging. Throughout the first few weeks, we focused on classes, sub-classes, inheritance, exceptions and recursion.

I worked in a group of three for Assignment 1. The assignment was basically my first time dealing with A.I (granted, it was very simple A.I). The idea of the assignment was to create classes and sub-classes of those classes to create a text-based game that you could play against a computer. We had to create the game called "Subtract A Square", where each player subtracts a square number no larger than the current number. The last person to make a subtraction wins. This game involved 5 classes: a game state class, which keeps track of the current state of the game. The subtract square class, which is a sub-class of game state keeps track of the game state specific to subtract square. Then there is a strategy class, and a specific sub-class for strategy used for subtract a square, which just generates a random integer for the computer to choose (simple A.I). Then there is the game view class which keeps track of the game, who's turn it is, whether a move is legal and basically runs the game. The reason for all the inheritance and sub-classes is, for future assignments, we will be adding more specific games and having the general parent classes will make this much easier.

Since these topics, we have been learning recursion. This blog post was very interesting to read about recursion: https://nicoleslog.wordpress.com. The blogger raised some very good points about recursion. They asked three key questions:

  1. What is needed in recursion?
  2. How does recursion work?
  3. What are the benefits of recursion?
I am going to think more about these questions and return next week with more information on recursion. Wish me luck on Wednesday's midterm!