Well, another week of CSC148 and boy were sub classes a pain. Actually I had learned about sub classes back in high school and how they could use the functions of the class they inherit from but it was slightly different since I learned how to do this in Java. There are a few small differences on how inheritance works but the idea is more or less the same. The sub class has all the same attributes as the class it inherits from and is also able to use any of the functions created for the master class. In addition, these methods can be slightly modified so they perform different thing when working with a specific subclass. For example, in our lab we made a Vehicle class and a subclass Car. The Car sub class could have used the method to get somewhere but it could be modified such that a car uses the fuel efficiency x2 in order to get to where they wanted to go. Overall sub classes are extremely useful since the methods do not need to be recreated for each subclass since they inherit it from the master class and they can have their own methods that the main class cannot access.
Now, moving on to recursion, it's about the same as what we did in high school as well. In high school we traced functions until we had reached the "base case" or in other words, when the recursion should stop and you begin going back up from the recursive method you went down. It's a bit weird now that we have to look at one case and then when we deal with a different case that contains the old one, we use what we got before but looking back at it, it does appear to save a lot of time when we get into much bigger cases since it's broken down into things we've seen already. I actually plan on going through a few more examples of recursion to refresh my memory a bit and apply what we learned in the lecture about looking back on old examples.
Well that's about it for this weeks post... now I'm going to head back to study for my physics term test coming up pretty soon...
Sunday, 2 February 2014
Thursday, 23 January 2014
Object Oriented Programming
Well, this is my first SLOG so I'm not exactly sure how to start this off but I guess I'll start talking about how I feel about the course work we've done so far on object oriented programming. To be honest, the first 2 weeks of lecture and lab were pretty easy for me. The classes and methods that were taught to us I learned in both the end of CSC108 and I spent half an high school semester learning about object oriented programming. There were a few minor differences from the things I learned from high school since we programmed in Java but the ideas were more or less the same. Finally using objects again, it made me realize how much easier it is to associate multiple things to one object than to try and put them all together by having them at the same index but in different lists. Creating the methods in Python are slightly different than how we did it in Java and the first week was a bit challenging but after going through a few more examples in the lecture and making a few methods of my own for the Stack class, I feel like I've gotten the hang of the basics in object oriented programming in Python.
Now then, about the assignments and labs we've done up to this point, they honestly weren't that hard yet. The square root assignment was a bit weird because we had to use the Newton Method but after a bit of thinking and trial and error, it only took me a few minutes to code. The dog and play classes were extremely easy as I already understood how creating classes and their methods worked so that wasn't a huge challenge for me. For the labs, I honestly found the first lab a lot more confusing than the second one. The second one was dealing with stacks and queues and back in high school, we actually did this already, making a stack and creating its methods and same with queues. The slight difference is that our stack and queue sizes were initialized at the beginning and the size of the stack or queue could not be bigger than what we initialized it to. Also when I talked to the T.A. about what I knew, he told me the queue would read just from the "head" of the queue to the end. In Java, we had both a head and a tail since the size was predetermined and the tail would go back to the beginning if we tried to add anymore to the queue. The queue we made read from head to tail since we were reusing old spaces in Java. Well that's enough about the second lab, in the first lab it wasn't really hard, rather it was hard to follow what exactly the lab was asking us to do. Me and my partner ended up getting stuck creating one of the methods and we never got time to reach the second activity sadly. The method we got stuck on we solved eventually but it took us way too long and in the end, the T.A. showed everyone how we could have done it a lot more simpler. It really showed me and my partner how thinking about how to do something in different ways can lead to a much, much easier time coding. Overall, the activities and labs for the first few weeks regarding object oriented programming weren't that hard and was a nice review.
I never actually talked about object oriented program in the first few paragraphs so I'm going to be summarizing what I know and learned about it from the lectures and notes we took. Object oriented programming is using objects which contain data types associated with each object and a set of procedures or methods that can be used on that object to do certain things like modifying the data or retrieving it. An object is a single instance of a class which is initialized by passing parameters into an __init__ method. If no __init__ method is created, then the object will be an instance of that class with no data currently in it. Afterwards, methods are created in order to perform certain actions on that object. Some examples are passing new information to be stored within that object, getting that information back and returning it or modifying the existing data in the object. All those methods are bound to the class that they are created in so only objects of that class can use those methods in order to perform the action. Object oriented programming is designed so that the methods can be reused by many other people if they are creating objects using the class you created and also is designed so that the information inside the object is not accessible unless methods are created to pull the information out as the user should only be able to manipulate the information using the methods only and not directly modifying the object. Well that's about the end of my summary on object oriented programming, plenty more SLOGs to come about what else we do in CSC148!
Now then, about the assignments and labs we've done up to this point, they honestly weren't that hard yet. The square root assignment was a bit weird because we had to use the Newton Method but after a bit of thinking and trial and error, it only took me a few minutes to code. The dog and play classes were extremely easy as I already understood how creating classes and their methods worked so that wasn't a huge challenge for me. For the labs, I honestly found the first lab a lot more confusing than the second one. The second one was dealing with stacks and queues and back in high school, we actually did this already, making a stack and creating its methods and same with queues. The slight difference is that our stack and queue sizes were initialized at the beginning and the size of the stack or queue could not be bigger than what we initialized it to. Also when I talked to the T.A. about what I knew, he told me the queue would read just from the "head" of the queue to the end. In Java, we had both a head and a tail since the size was predetermined and the tail would go back to the beginning if we tried to add anymore to the queue. The queue we made read from head to tail since we were reusing old spaces in Java. Well that's enough about the second lab, in the first lab it wasn't really hard, rather it was hard to follow what exactly the lab was asking us to do. Me and my partner ended up getting stuck creating one of the methods and we never got time to reach the second activity sadly. The method we got stuck on we solved eventually but it took us way too long and in the end, the T.A. showed everyone how we could have done it a lot more simpler. It really showed me and my partner how thinking about how to do something in different ways can lead to a much, much easier time coding. Overall, the activities and labs for the first few weeks regarding object oriented programming weren't that hard and was a nice review.
I never actually talked about object oriented program in the first few paragraphs so I'm going to be summarizing what I know and learned about it from the lectures and notes we took. Object oriented programming is using objects which contain data types associated with each object and a set of procedures or methods that can be used on that object to do certain things like modifying the data or retrieving it. An object is a single instance of a class which is initialized by passing parameters into an __init__ method. If no __init__ method is created, then the object will be an instance of that class with no data currently in it. Afterwards, methods are created in order to perform certain actions on that object. Some examples are passing new information to be stored within that object, getting that information back and returning it or modifying the existing data in the object. All those methods are bound to the class that they are created in so only objects of that class can use those methods in order to perform the action. Object oriented programming is designed so that the methods can be reused by many other people if they are creating objects using the class you created and also is designed so that the information inside the object is not accessible unless methods are created to pull the information out as the user should only be able to manipulate the information using the methods only and not directly modifying the object. Well that's about the end of my summary on object oriented programming, plenty more SLOGs to come about what else we do in CSC148!
Subscribe to:
Posts (Atom)