Object oriented programming is a fascinating concept. It opens the door to allow you to do many abstract things with python. I first realized this while working on the Subtract Square game for assignment 1. Object oriented programming focuses on using classes to make objects that are used to store data. For example in assignment 1, we made a class for GameState(GS). This was a general class that was used to keep track of a general game. It had different instance variables which are variables of the class to store information about the class. This general class stored information like whether or not it was the computers move, a list of available moves and whether or not the game is over. Now most of this information is useless without knowing information from a specific game since you wouldn't know when to update these variables.
So this is where the game specific classes come into play. We made a SubtractSquareGameState (SSGS) class. This class in conjunction with the general GS class completes the game. While initializing the SSGS class we inherited the GS class. So we automatically get the variables in the GS class. So we are able to update the variables from the GS class in the SSGS class because we now know specific information about the game. This assignment gave me a great understanding of how useful inheritance and Object Oriented Programming is. This entire game could have easily been done without the use of objects however doing it this way allows you to make multiple similar games since the groundwork for the game is already laid out in the general class. You would just need to program the specific code for the game you need to add. Where as if you were to do it without objects you would have lots of duplicate code.
Sunday, 22 February 2015
Sunday, 8 February 2015
Impressions of tracing recursion
Tracing code for recursive functions is a very fun thing to do. It's almost like you're working with nesting dolls or peeling layers off of an onion. You pass the argument through the function which refines it a little and passes it again through the function until eventually it hits a stopping point and is able to connect everything together. Tracing it allows you to see how the computer analyzes the function calls. Each call of the function is like another layer being unraveled to try and understand the thing as a whole.
Monday, 2 February 2015
What assignment 1 had taught me
Assignment has taught me a lot of things about programming that I was just never comfortable with before. In my final year of high school I briefly covered classes and objects however I couldn't think of any practical applications for it and I had trouble understanding what was going on. However now that i have completed and submitted assignment I have a very clear understanding of the various concepts associated with classes and objects. Thinks like overriding functions and inheriting classes that were once a mystery to me are now something that I believe I could incorporate in future projects with relative ease.
Subscribe to:
Posts (Atom)