Sunday, 9 February 2014

A Look Back at Week 5: Scopes and Assignment 1!

Hello readers!

We're into week 5, steam-rolling through the winter term and the assignments and tests are sure piling up! The latest (well first really) CSC148 assignment is based on the famous Towers of Hanoi game. Instead of the usual 3 pegs, our version has us dealing with 4.

What's really interesting about this is that the most optimal solution to Towers of Hanoi with more than 4 pegs has yet to be proven! Many great minds have probably tried solving this problem and it feels great knowing that we are going through the same thinking process they went through!

I chose to work alone as I usually do for CS assignments; though I was first a bit frustrated with understanding how assignment one was meant to be structured, I did eventually figure it out (thanks to everyone on the Piazza forums!). It was nice to see how the different topics we discussed in class so far (inheritance, basic data structures, recursion etc.) fit together to make up a working solution.

Although I haven't yet managed to find the most optimal algorithm for solving the 'four stool (or peg)' Towers of Hanoi game, I have come quite close to it. Hopefully, I will discuss my solution (and alternatives) more thoroughly after the assignment deadline has passed ( to give everyone a fair chance of course :-] ) - but the hardest part by far has been figuring out what values of 'i' to use; I think the answer to the most optimal solution lies there - though I haven't found it yet.

Besides the assignment, the other highlight of the week was the lecture topic on scope. This is yet another familiar topic for me though I haven't used it much in the past. My past instructors told us to avoid using global variables (most of the time at least) as they can make code harder to understand and can start polluting namespace.

Is was a little difficult, but after looking through the examples (of predicting outcomes) in lecture, I was able to refresh most of my memory on this topic.

I've also finally had a chance to read through some other Slogger's posts. A couple that really caught my eye were: cynnGAH's Slog (http://148journey.blogspot.ca/) and Ada Ene's Slog (http://adauoftcsc148.blogspot.ca/). They were definitely fun and informative reads. cyannGAH's Slog was particularly fun to read as they summed up the weeks topics in a rather witty and fun way. It's nice to see how these Slogger's and others have dealt with understanding the topics discussed in class and it definately gives you a neat sense of perspective to see the topics through someone else's eyes!

That's all for this week - good look on your mid-terms everyone!

Monday, 3 February 2014

Recursion and Cheese!

     Week 4 has come and gone: The central topic this week was recursion. Though it was an overwhelming idea at first, there was one example that stood out amongst the rest in it's explanatory power: Thinking of a problem as a set of smaller but similar problems. Then, consider the subsets of the same problem within those subsets. You carry on this process until the base case is reached and then add everything together to solve the problem.

     Working through some recursive examples was a bit difficult at first since I was treating every subset of the problem individually rather than seeing the same solution work for every subset and then ultimately culminate to the final solution.

     All in all, recursion is definately a great addition to my 'programming toolbox' and I see many uses (both past and present) for it.

    Speaking of present uses of recursion, the next topic of the week was Assignment 1.
A1 is based on the famous Towers of Hanoi problem. This assignment has us trying to move stacks of cheese with towers of hanoi-esque rules.

     Though the assignment (currently working on it) seems quite challenging, I like seeing all that I've learned being put to use in one exercise.

     I recognize that many aspects of the programming world emphasize teamwork and coordination, but I have decided to (for now) work alone. This will give me the oppurtunity to test my comprehension of learned topics in a rigourous way. Hopefully that will be good prep for the upcoming mid-term.

     Well, that's all for this week - good luck to all on assignment 1!

 

Wednesday, 22 January 2014

Object-Oriented Programming

     Having worked with the concepts of inheritance, composition and exceptions in the past, the third of week of CSC148 felt like, in general, an effective and comprehensive review. Being new to Python, it was, as one might expect, interesting to compare the ways in which Python implements these programming concepts in contrast to other OOP languages like C++ and Java.

     Generally speaking, I find making use of classes in Python to be easy and intuitive. I particularly enjoy the way in which Object-Oriented Programming works to structure my solutions in a coherent manner - for example, instead of outright treating an ADT, like a list, as a stack, it is much more intuitive to encapsulate all methods related to stacks in a single class and then call on that class as needed in the future. 

     I felt that, not only is it less tedious to code in such a paradigm, but it is also easier to understand and make future use of chunks of code relating to a particular ADT or set of methods (i.e. stacks, queues or a class of mathematical operations). In other words, the aspect of reuasbility - just as in procedural programming - is perhaps one of the most appealing features of OOP. In summary, the amount of structure and coherence that  OOP brings when coding a solution to a problem is what I think is the most enjoyable aspect of coding with an OOP paradigm in mind.

     Now that my general overview/ analysis of this the OOP discussed thus far in the course is over, I will now move on to some challenges that arose during my experiences with OOP in these first few weeks.

     My first challenge was centered around the concept of 'flexibility' of my classes: How might I structure my classes in way where others, and myself, could use those same classes for solving a variety (of different) problems? What I mean is this: I know that I am writing a certain class to help with my solution to one particular problem, but isn't one of the central ideas of OOP reusability? Will this same class benefit me in other cases, or will I (or others) need to modify it later to suit my (new) purpose? 

    What these questions lead me to was the idea that, when I write my classes, I should bear in mind  different ways in which someone (or myself) might want to interact with this class. I should then code my classes in a way that is not just tied or suited to the problem at hand - i.e. I should include helpful methods that can may be used to manipulate the class in different ways than what I currently need. Of course, I needn't stress over every possible use of this class but, at the very least, the class should be (except in special cases) general enough that it is able to be used in different ways.

     Am I putting too much emphasis on reusability? Perhaps. But I believe firmly that this should be an idea at the back of the mind of any serious user of a OOP paradigm. 

     I will mention one other OOP challenge I encountered these past few weeks: the fact that, unlike C++ or Java, Python does not consider access levels in classes (private, public variables etc.). This is a concept that I learned to work with when I first started with the OOP paradigm in other languages - and it is a concept that I stuck with throughout my studies in computer science. 

     Though it is not a major issue, I know that it will take me a while to adjust to thinking object-orientedly without considering access levels, I feel that it also somewhat liberating to know that I don't need to worry about programs that might access a variable their not supposed to and hence, not use the class as intended. On the flip side, I will need to more careful when I use my own (or other's) classes!