Friday, 31 January 2014

Week #4: Tracing Recursion, Using Unittest, and Starting Assignment #1

     This week I found the material we covered in lecture to be substantially easier to follow. Generally speaking recursive functions are not something I struggle with -- whether I am writing them or tracing them.

     That being said, I found the lab this week substantially more difficult. Although, my partner and I implemented the required classes promptly, neither of us had had much practice using unittest to test our programs. We had to look up unittest in the Python 3.3.3 documentation and carefully go through the example posted, before we attempted to apply it to our specific program. While we spent more time debugging the syntax errors and spelling mistakes in our unittest modules than Motorized and its subclasses, we did eventually get all of the modules working.

     As far as assignment one goes, I have now completed the module headers for TOAHModel.py, and have begun to implement them. I was not entirely sure how to represent the cheeses on the stools at first, as I could not tell whether the stool counted as a 'cheese' or not. However, by searching through the course forum, I found that another student had had the same question, and an answer had been posted.

     Overall, this week I have learned that when I find myself stuck there are plenty of online resources I can turn to to get myself 'unstuck'.

Thursday, 23 January 2014

Week #3: Object-Oriented Programming

            During the first two weeks of class I was not concerned about delving into object-oriented programming. I believed that object-oriented programming was essentially the same as the programming I had done in 108, except it sorted the functions into classes to improve organization. Any new concepts that were introduced – such as ‘property’, list comprehensions, and even recursion – were concepts that I felt I was able to understand completely just by thinking through the examples (i.e. sum_list) that we were shown in lecture and working through the lab exercise.

            This week, however, – whether it was due to the material itself, or the fact that I was sick with a cold – I had trouble paying attention in class and found myself substantially more overwhelmed by the material. I followed along well enough when it came to inheritance and composition, but when that was combined with the example of the code on exceptions I was lost. I also had no clue how the str and repr method were related.

            To resolve this, I began by reading the readings for this week. The reading on Inheritance vs. Composition really clarified for me how class hierarchy works, and how different methods can take priority based on when and how they are called (i.e. if the child class has a method that has the same name as a parent class the child classes method will have priority unless you alter this by using something like the super function). Even though, we went over this topic in lecture, sitting down and having a chance to go through the material at my own pace made a difference.

            There was not a lot of information in the readings on __str__ vs __repr__, so I looked up some tutorials on YouTube and questions that were asked in forums. These gave me a vague understanding of their differences. __repr___ is a representation of an object intended for the developer whereas, __str__ is a readable printable representation of the object. I still did not entirely understood how the worked though.

            I decided to copy and paste some of the examples I found into Wing and try them out myself. I then altered them based on the questions I had about the material. From this I learned that __repr__ is a superclass to __str__. I also learned that if you try to print an object that is a tuple or list, python will use the __repr__ representation rather than __str___, unless you specifically call the __str__ method on each item. However, for non-iterables, it prints the object’s __str__ representation.

            Testing out the code in this way worked so well for understanding each of those methods that I decided to use a similar strategy in order to understand the exception code I struggled with in lecture. Unsurprisingly, commenting out certain portions myself and running the code on my computer really clarified both inheritance and exceptions for me.

            This week I learned that object-oriented programming is a lot more than writing functions as I always had, and sticking them in something called a class. It is about directly grouping your data with the methods that will be performed on/with it. It is also, about clarity and organization not only for you, but also for other programmers who may want to use your code or compose it with their own. Mostly, it stems from the idea that programs are not laundry lists of different functions. They are like webs. Preferably organized webs,