The first few things we learned about object oriented programming( OOP) were the basics. We were taught that object oriented programming was about creating something (an object) that is created by a class. If we were to create the object elevator, we'd need to have methods that take the elevator up and one that takes the elevator down. We could also have a method to call for help if there was an emergency. These methods help create this elevator and make the elevator an actual, functioning elevator. We also had to create an __init__ method for classes and this method helps to start up anything that we need prior to creating this object. For example, in the __init__ method for class elevator, we could create a list that would contain how many floors there are in the building. Then, the method for moving up can use this list to figure out if we even have to floor and if it does exist, take the person to that floor. The str and repr methods are pretty similar except the str method is a "prettier" version of the repr method. It needs to be as such because this is what is printed for the user to see and the repr is for the programmer. They are both representations of the class.
The labs themselves are really helpful because I get to play around with the topics we were introduced to. I always try out the labs before the actual lab starts. I haven't had any issues thus far because the topics are pretty self explanatory and if I do have an issue, just playing around in the labs helps answer my question.
I really like learning by myself because I think I get the most learning experience when I learn from my mistakes so while learning about classes, I would keep making new classes and running them to see what values and inputs I get. In the end, it helped me figure out what I wasn't understanding or missing so I could fix it.
Sunday, 15 February 2015
Saturday, 7 February 2015
Recursion
Recursion to me was fun. I had heard about recursion before but I had never been formally taught it nor had I seen an example. Personally, I think recursion was the most important and interesting topic we learned about. I had no idea that we could use a function in its own body. It's important when we have nested lists if we wish to do something with the elements of the list. For example, if we want to add up the elements of a nested list, we'd have to use recursion. It is important to have a base case in any recursive function so it can end somewhere. For example, if we wanted to create a function that finds the sum for a nested list, we can check if something is a list and if it is, then go through the list recursively but if it isn't, then just leave it. Then we can add up and return all the numbers using sum.
I think it's a really useful tool to have especially when there is no guarantee of what the parameter could be. For example, if we were required to find the max number from a list and we could be presented with a nested list, we would need to get the max of each list in that list. This is where recursion helps. It can save a lot of effort in complex cases where a step has to be repeated again and again to get the desired solution
The only instance where I had to work with recursion was in the labs. It was my first time implementing recursion. My favourite lab was the one for week 5. We had to work with stacks. We had to create a function that could pick apart a list and add each element to a stack. It seems easy if we were given a list with a depth of 0 but once we are given a list that had more lists inside, recursion became useful. Though recursion is useful, it is important to have a way to end the recursive loop or else it will keep on looping. In other words, it is important to have a base case.
When it came to recursion, it got a little tricky trying to understand it completely because you have to be aware of how many times the recursive call is made. It can get messy. To learn recursion better, looked at different function and ran recursive calls manually to try and figure out the outcome. Then I ran the function on python to check my answer.
The midterm this week also had recursion in it and it wasn't too difficult. It's like a puzzle, you have to go through everything in steps to figure out one by one to get the correct output.
I think it's a really useful tool to have especially when there is no guarantee of what the parameter could be. For example, if we were required to find the max number from a list and we could be presented with a nested list, we would need to get the max of each list in that list. This is where recursion helps. It can save a lot of effort in complex cases where a step has to be repeated again and again to get the desired solution
The only instance where I had to work with recursion was in the labs. It was my first time implementing recursion. My favourite lab was the one for week 5. We had to work with stacks. We had to create a function that could pick apart a list and add each element to a stack. It seems easy if we were given a list with a depth of 0 but once we are given a list that had more lists inside, recursion became useful. Though recursion is useful, it is important to have a way to end the recursive loop or else it will keep on looping. In other words, it is important to have a base case.
When it came to recursion, it got a little tricky trying to understand it completely because you have to be aware of how many times the recursive call is made. It can get messy. To learn recursion better, looked at different function and ran recursive calls manually to try and figure out the outcome. Then I ran the function on python to check my answer.
The midterm this week also had recursion in it and it wasn't too difficult. It's like a puzzle, you have to go through everything in steps to figure out one by one to get the correct output.
Sunday, 1 February 2015
The past few weeks
The last two weeks were pretty fun for me. I had to touch up on my classes so I watched a few youtube videos about how to code them in python. It was very insightful and I found myself watching videos about object oriented programming. Watching the videos really helped me understand classes. I was having trouble understanding what exactly initialization was supposed to be for until we made classes in the labs and I realized it was used to construct anything that we needed before any method is called. For example, if we wanted to create a game where we have a character with health, we'd want to initialize his health first (i.e.self.health = 100%) before we use methods to take away health. Classes are an easy way to be organized. You can keep methods that all related to a certain thing in a class so that you can access it.
The assignment was fun to code. It was a little tricky finding a way to code it so it wasn't specific to the generic classes but I had a really awesome partner and we checked on piazza when we needed to get a better understanding of what the assignment really required us to do. I have never had a partner in any CS class so it was fun getting to collaborate with another brain. We had to discuss all parts of the assignment when normally, I'd just implement whatever I wanted to.
I think the first few weeks were really fun. I was especially impressed with list comprehension because an entire for loop can be replaced with just one line to get the same result.I also had never heard of the module turtle before so being able to learn that it can draw was really amazing.
My professor is Danny and I think he's a really good teacher. He explains concepts very clearly and is very kind. I like the fact that he tries to learn and remember everyone's names. I'm really looking forward to the rest of this class so I can learn more about python and the things I can do and code with it.
The assignment was fun to code. It was a little tricky finding a way to code it so it wasn't specific to the generic classes but I had a really awesome partner and we checked on piazza when we needed to get a better understanding of what the assignment really required us to do. I have never had a partner in any CS class so it was fun getting to collaborate with another brain. We had to discuss all parts of the assignment when normally, I'd just implement whatever I wanted to.
I think the first few weeks were really fun. I was especially impressed with list comprehension because an entire for loop can be replaced with just one line to get the same result.I also had never heard of the module turtle before so being able to learn that it can draw was really amazing.
My professor is Danny and I think he's a really good teacher. He explains concepts very clearly and is very kind. I like the fact that he tries to learn and remember everyone's names. I'm really looking forward to the rest of this class so I can learn more about python and the things I can do and code with it.
Subscribe to:
Posts (Atom)