Thursday, 20 February 2014

Week 7 - Recursion

    It has been several weeks since I've made a post and I feel that I have made great improvements in my programming skills and understanding of content. For example, I did not understand the property function at all, and I also felt that it was useless. However, after I went back to take a look at it once more, I finally understood its importance. It stops the user from changing an attribute of a class in a way that the programmer would not want it to be changed. We can do this by writing a setter method that is called every time the user tries to assign to an attribute of a class. We would also need a getter method otherwise the private attribute would be unreadable. I have even used the property function within some of my code so I feel that I am comfortable with it. This is just one of several topics that I feel I have progressed in. Others would be handling exceptions, object oriented programming, and inheritance. I have made progressions through several hours of practice, and by working through and completing assignment 1. I believe that lots of practice is the key to doing well in this course, at least it is for me because I often have trouble grasping the concepts at first sight during lecture.

    While I have progressed greatly in some aspects of this course, I still find recursion to be quite challenging. When we first started learning about it, I had absolutely no idea what was going on because I found that calling the function itself within its own definition was just mind boggling. Another reason for my struggles with recursion is that it is somewhat difficult to trace. I feel that there are so many things happening within it that I get confused while tracing it. I don't mean just tracing on paper but rather visualizing and dissecting what happens in each step. I feel that visualizing each step for a function helps me understand where potential problems might lie and how the function actually works but I have a considerably difficult time doing this with a recursive function call. After several weeks of working with it in lecture, the assignment, and in labs, I have understood some parts of a recursive function. For example, I acknowledge that there has to be a base case for the function to eventually reach otherwise recursion depth will be exceeded. With this information, I know that the first step to writing a recursive function is to write the base case first. I start having trouble with the rest of the function after this step. I am now able to write simple recursive functions such as the nested depth of a list or a sum of the elements in a nested list but I still require too much time to write some of the slightly more complex recursive functions. I believe that I require more practice with writing recursive functions because I have hardly attempted them outside of labs, lecture, and the assignment. I know that writing recursive functions is an essential tool for programming and so I will continue to practice with them until I am fully comfortable with them.

Sunday, 26 January 2014

Week 3 SLOG: Object-Oriented Programming

     Last term in CSC108, I believed objected-oriented programming to be the most useless, tedious and annoying part of the course. I did not understand the purpose of classes, as they seemed to be a much more complex and inconvenient way of creating functions. While I acknowledge that I do not have a thorough understanding of object-oriented programming, I believe I have made strides in understanding its purpose. An instance of a class has specific data and attributes that are unique to that class. These features assist greatly in keeping everything organized. For example, I would imagine that Facebook performs well because of its usage of classes. A profile, for example, could possibly be a class that Facebook uses to create profiles for people that sign up for it. It would have attributes such as number of friends, age and date of birth and methods such as adding another user as a friend. I could not imagine how this would be accomplished without the usage of classes since the code would be much more complex and disorganized. This example is just to show that I have a new perspective on classes and their usefulness. I find it interesting that classes can inherit properties of other classes, although I do not understand the purpose of this since we could just have one class with all the properties of similar classes. With all the great benefits of classes, I still do believe that they are somewhat complex to develop at times. For example, I find that having to create __str__ and __eq__ methods very inconvenient and somewhat time consuming. I am also moderately uncomfortable with implementing such methods because I do not understand how they work. For example, I don't quite understand why using the == operator on two instances of a class will check if their memory addresses are equal rather than their values. This is one of the several aspects of classes that I have trouble comprehending.

      I believe I can solve my troubles with object-oriented programming by consistent practice with developing them, and by analyzing its properties thoroughly from top to bottom so that I will understand why they work the way they do. I believe that this solution is working so far because I have a thorough understanding of how some of the features in object-oriented programming works. For example, I know that the __init__ method is used to give an instance of a class its specific attributes and data, depending on the class of course. This was an example of a concept that I was struggling with before but now I am very comfortable with. I suspect that the reasons for my problems with object oriented programming are because I started working with them before really understanding why and how they work. With this post, I hope to have conveyed my thoughts on object-oriented programming rather than reiterating its several features.