Friday, 13 February 2015

Summary of Object Oriented Programming (Week 6 SLOG)

In the past six weeks I feel that I have gained a decent understanding of classes and basic recursion. Creating our own classes help us solve some problems that would be difficult using only the default python classes. What's interesting about python is that every object stems from the object class, and thus inherit certain methods from it. Even though we can create our own objects (such as different types) de nouveau, they can share a number of properties with other python types. In fact, I learned that we can represent many different problems such as registries, games, and even antiquated mathematical operations using classes. The use of subclasses allows the already flexible idea of objects to fit a greater number of problems. Inherited values and methods allow subclasses have their own identity, while still being related to their parent classes in a way. While completing my assignment, I came across the idea of polymorphism: calling the same method but having it perform different operations. It appeared in my Strategy Class, where I called a method that carried out a move based on the currently chosen strategy. Since the methods had the same name, I could call it in a loop, while only changing the state of the current player's turn. Polymorphism spared me writing additional unnecessary code, and I can see it being a powerful tool.

Speaking of powerful tools, recursion seems to help us solve problems in areas where linear or looped code may have trouble. Not only is it powerful, it is also relatively simple code, with only a base case that is called on the most simple case, and a general case for more complicated arguments. However, these general cases may not always be so simple. In lab 6, I discovered that the general case may span some lines in order to cover every case and achieve the desired result. I think I worry too much about the code executing properly; some days I may attempt to trace out relatively complicated recursive code, sometimes resulting in more confusion. I found that if I just trust that the code will execute properly, I can work with a clearer mind. Interestingly, I have been seeing recursion more and more in my daily life. As a hobby, I enjoy learning about things that sound contradictory to common sense. I learned about fractals a few years ago, but I did not realize that they are based on recursion. Learning about object oriented programming has increased my appreciation for the natural world.

No comments:

Post a Comment