Wednesday, February 25, 2015
Object Oriented Programming (Week 7)
For my summary of object-oriented programming concepts, please see and mark my post from Week 6.
Friday, February 13, 2015
Summary of object-oriented programming concepts
Object-oriented programming centres around several important concepts, all of which are interconnected, and all of which centre around the concept of the objects themselves, and the ability to perform functions on objects, or to assign objects to variables (such that a variable name contains an object). Objects are things that you can create and assign to a variable name. They include many different types, including float, int, dict, bool, str, list, and many others. Each of these has methods and attributes Classes are specific object types which you can define and write methods and attributes within just like types. You can create an object within a class by making a variable name equal to the class, followed by parentheses enclosing any arguments that the __init__ method of the class takes in other than self - ie, any global variables. Inheritance is when one class is defined in terms of another in the initial 'class MyClass' statement - which might, in this case, mean the statement would read 'class MyFavouriteClass(MyClass)'. In this case, the class MyFavouriteClass would inherit the attributes and methods of MyClass, if it is initialized in the __init__ method of MyFavourite class like so: 'MyClass.__init__(self, globalvariable1, globalvariable2)'.
All of these concepts, as mentioned earlier, centre around the object, and how to create and manipulate objects in different - albeit very interconnected - ways.
Thursday, February 5, 2015
Thoughts on tracing recursion
Recursion has indeed gotten easier and the main things that helped with this were, I think, the exercise sheets. Those sheets gave me the practice I needed to be confident in my understanding of recursion on the test. Tracing recursive functions on that lab and exercise sheet REALLY helped me understand how they work, to the point that when studying for the test I wrote several recursive functions with relatively little difficulty (only to then go on Piazza and realize we didn't need to write recursive code for the test, but ah well, for some odd reason I feel like that will come in handy anyways... I wonder why that could be...). The tracing allowed me to stop seeing recursion as this great big scary computer programming concept which people who had learned previously had told me was very hard to get right, and instead view it in a mathematical way. This not only made it less intimidating to approach, but made it very easy to see how a recursive function 'unravels', so to speak. Tracing recursion before actually writing recursive code is going to help me actually understand the nitty-gritty of how it works rather than knowing how to implement in an 'I-just-memorized-this-formula' sort of way. Debugging when writing future recursive code will be infinitely easier because of this, as will writing more complicated recursive functions. In short, the number of functions we had to trace was a huge help. At this point in the course I actually like recursion (something that terrified me a bit a week ago) better than classes and inheritance (not that I don't like those - I do - I just find recursion more satisfying). I may live to rue these words when we get into more complicated recursion (I'm going to go knock on wood now) but for now I will enjoy this strange and lovely feeling of having a handle on what is going on.
Subscribe to:
Posts (Atom)