Wednesday 25 February 2015

WEEK 7: Debrief and Object-Oriented Programming (OOP)



     Success!

     Even a small challenge to overcome is a big step for a beginner programmer like me. I practiced recursion over the break and I finally got the hang of it! It may have taken many, many trials but I can say with some confidence that I understand recursion to some extent now. This week we are going to add on to what we already know using Binary Trees and practice recursion a tad bit more. It always feels like I've fallen behind when I don't finish my lab but I'm making an effort to completing it before the next lab.

     Now on to this week's topic: OOP

     I chose to write about OOP instead of recursion because I want to take this opportunity to step back and analyze for myself exactly what it is about OOP that I know and also to review the aspects of it I didn't fully understand weeks ago (when doing the first assignment). What is an object? What does it mean to be object oriented? These were the first questions I asked on the first day of classes. Here's what I know now:

     In python, all values are individual objects held a specific memory address that stores information and behavior (type of value and operations for it) of that object. So when we call an object we are calling onto the content (information/value) that it's memory address holds (unless directed otherwise).

    Within this type of programming we can also create a new class of objects. By creating a new class we can create any type of objects that operate in the way we design it to (with it's own functions, methods and restrictions). Here's an example of how a class is created:

    class ClassName:

           """This creates a new class. Your description of the class goes here."""

           def __init__(self):
                 """ (ClassName, type) -> NoneType
                 This method initializes ClassName with it's required parameters.
                 """
                 # initialize any parameters here.

           def specific_class_function(self):
                 """ (ClassName) -> Value
                  This method uses the argument to return something.
                  """
                  # implement function here based on intended return value and parameters.

use __str__ to create a string method representative of ClassName

use __repr__ to create an official string method representative of ClassName

use  __eq__ to create a method that compares two ClassName objects to see if they are equivalent.

Subclasses are child class of the parent class it takes as it's argument. A subclass inherits everything from the parent class and can also override the functions defined in the parent class.

    class SubclassName(ClassName):

           """This creates a subclass of ClassName. It inherits everything from ClassName."""

           def __init__(self):
                 """ (ClassName) -> NoneType
                  This method initializes SubclassName with it's required parameters.
                  """

Creating new objects can be simple or complicated as you want it to be and this is what makes OOP subjective and useful. The more we learn about OOP the more options we have at our disposal.

Cheers

(If there is any conceptual errors please let me know!)

Friday 13 February 2015

WEEK 6 ~ Trees and Recursive Functions

     I'm not all too sure what I find more difficult: writing a recursive function or understanding the trees well enough to write the correct recursive function.

     The latest lab exercise on trees seemed simple at first but got pretty difficult the more we worked at it. My partner and I could not pass all the doctests no matter what we tried. Some code will pass more tests then the others but it was hard to tell if we were on the right track or if it was just worked under specific circumstances. It started to get frustrating which only made it harder. This weekend I'm going to try to finish up the lab exercise and ask for some hints from peers along the way.

     The new assignment requires us to implement recursion so I'm definitely going to spend some time during this reading week to practice recursion and do some of the extra exercises from the previous labs. As soon as I get through that I'm going to start on the assignment so I have enough time to fix the bugs I'll have in this assignment.

    Cheers

Friday 6 February 2015

WEEK 5 ~ Midterm1 Done and New Code Tricks

     Our first midterm is over!

     I'd say if there was anything good about having a midterm exam is that it forces us to really take time to understand our work by an early date. Keeps me on track but it also shows me just how much I don't really know that well! I realized as I was writing my aid sheet for the exam that reading new code is much more easier for me than writing my own code in the same way. In fact, I'm still only fluent in the basic for loops and if statements and haven't gotten the idea of implementation of commas yet (i.e. "tuple constructor syntax"). But I'm working on it.

     As for what we are learning in class: tracing  recursion, stack and queues is surprisingly enjoyable. However, as mentioned, it isn't enough to know how to trace it, I need to get better at implementing my recursive functions, stacks and queues.

    On last weeks notes; I'm starting to get the hang of writing classes and subclasses. Making unittests help make sure my code is thorough but creating them is another difficulty for me. However, it might just all be a matter of time and practice. Here's hoping for improvement for next week!

    Cheers