Wednesday, 25 February 2015

Week 6: Review of OOP

Last summer I was playing a lot of Hearthstone, an online card game similar to Magic: The Gathering. I wanted to know the probabilities associated with drawing certain combinations of cards before a given turn. I tried to create a program that simulated a very large number of games while keeping track of which turn particular cards were seen by. This was before I was familiar with object-oriented programming so I approached the design of this program by constructing functions that attempted to create, mutate and examine lists of tuples. I was very disappointed with how the program took shape. Even with helper functions, the code was very hard to read, the overall design felt needlessly complex and eventually I gave up on it.

About a month ago I spent some time trying to redesign this program using OOP. Although I have yet to complete this program, it's clear that an object-oriented approach has significantly improved its design. Having attributes stored in classes helped me come up with a much more precise plan for what data I was tracking and what methods I need to make it all work. Figuring out how Card, Deck and Game objects should interact feels easier (and less error-prone) than figuring out how generic lists and tuples should interact. This resulted in the new implementation being significantly leaner than the old one. Also, while the original design had methods and data arranged without any apparent organization, having methods and data stored within classes has made the code more organized and readable. I found that OOP is very conducive to having organized code. This had two important consequences. First, it was much easier fix the code when a bug was found. Second, it is now much easier to extend the functionality of the program. I already have a few ideas for new questions that this program can answer and I anticipate that these changes will be significantly more straightforward to implement relative to the old design.

Although I'm sure that my program could be made to work without OOP, this experience showed me how in many cases, using classes is just the most natural and effective way to approach program design. Classes structure your thinking and they play a major role in organizing your code.

Sunday, 8 February 2015

Week 5: Tracing Recursion

The feature of recursion that stands out to me most is how clean recursive code appears. There are surely some horrible-looking recursive algorithms out there, but if I were to try to implement quicksort without any recursion, I'm sure that the code would be far more complicated than what was shown in lecture.

It's helpful that this concept is being introduced so gradually (we're learning how to read recursive code before we start having to write it), but I'm ready to dive right into this material! I'm really enjoying this course but I'm also looking forward to CS courses that move at slightly faster pace.

Sunday, 1 February 2015

Week 4: Impressions Of First Few Weeks

The CSC148 info sheet begins with the claim that the course aims to provide us with "the basics for approaching program design principles such as encapsulation, modularity, and information-hiding, comparing different program implementations for efficiency, and building powerful data structures". Something I find interesting to think about is what objectives a course might have apart from the ones that are explicitly stated.

First, this course appears to be promoting reading comprehension. In CSC108, the assignments mostly revolved around being able to understand a function description  and be able to implement it. In order to do well on the first assignment of CSC148, it's necessary that you be able to do read pages of descriptions and instructions, pick out the important chunks of information and be able to see the relationships between different chunks. Only once all this information has been synthesized can you actually begin to implement code.

Second, this course heavily promotes using your own discretion. In the labs and in the first assignment the majority of the details of the implementation of our programs are left entirely up to us. Personally I find this to be very liberating. While in 108 it was nice to simply be given a list of functions that needed to be written, I felt that because of the extra freedom, 148 makes room for more creative approaches to completing labs and assignments.

Ultimately, I think that these two "hidden" objectives are indicative of what this course is really about (apart from the obvious things stated in the opening paragraph of the info sheet). CSC148 is fundamentally about learning how to solve problems. I think that object-oriented programming, recursion, reading comprehension, etc, aren't part of this course simply because they're worth understanding for their own sake. Rather, they're part of this course because they teach first year CS students how to be better problem solvers.