Saturday, February 28, 2015

Entry 5: Object-Oriented Programming (Part 2)

     Last time, I discussed some basic information regarding OOP and how I became fond of the concept. Despite OOP being the most popular system of coding, it has its drawbacks (Keep in mind that these drawbacks are based on information collected from various sources, which will be included at the bottom of this post). First of all, OOP-based programs require more effort because they are more complex, thus, require more planning and preparation prior to coding. Secondly, OOP-based programs have more lines of code, which may lead to reduced application performance. I think these drawbacks are very minor because OOP-based programs require the collaboration of multiple programmers to successfully implement a program. As for the second drawback, this is virtually non-existent on today's systems because they are equipped components that trump the risk of reduced performance. From fast central processing units to solid state drives, all these components covert to a seamless experience, which is shown in the program.


     Recently, I read several blog posts of a few other students and I was surprised by the level of commonality regarding object-oriented programming. One of these posts was written by Alex Kuo and he too wrote about how classes are used to bring the system "together". Another post, written by Timothy Lock, wrote about the Turtle class and how Professor Heap used conventional OOP to use this class for various tasks. As I said in my last post, I already have experience in OOP, particularly with the Java programming language, but I believe I need more practice to become an expert. Hopefully, learning Python can enhance my ability to use OOP.


Saturday, February 14, 2015

Entry 4: Object-Oriented Programming Concepts

     I first encountered object-oriented programming back in high school. Specifically, in Grades 11 & 12, I learned Java and the basics of object-oriented programming. I was a little skeptical about the idea because I was unsure if there were any benefits (or drawbacks) to the idea. My first real encounter of programming was learning Visual Basic back in Grade 10. Essentially, learning that language was the reason I became interested in Computer Science because it was simple and straightforward. It took some time getting used to Java because the structure of developing a program was different compared to Visual Basic. So for the most part, I am familiar with the basic structure of object-oriented programming. 


A Cluster of OOP Languages


     OOP is composed of multiple objects, each containing its own set of data and functions. The advantage to this mode of programming is multiple objects can communicate to each other to perform a specific set of tasks. Visual Basic requires more effort because if an element requires changes, these changes must be made throughout the entire body of code. In my experience with Visual Basic, I created a program that simulates the card game "Black Jack" and it contained nearly 8000 lines of code. I say about 40% of the code was repetitive, which proves the efficiency of OOP. Another advantage to OOP over traditional programming is multiple instances of an object can be made by inheriting its definition. If I have multiple instances of an object and I wanted to modify a specific attribute, I can simply make the changes in its definition and these changes will apply to all the instances of that object. 

     As Professor Heap stated at the beginning of the semester, the most important virtue for first-year students is laziness and OOP perfectly fulfills this goal. 

Friday, February 6, 2015

Entry 3: Week 4 - Recursion & Term-Test

     The main topic of this week is called Recursion. It is essentially breaking up a problem into smaller sub-problems until the problem can be solved immediately with no required steps. At first, it seemed fairly straight-forward, thanks to Professor Heap's example of the function "sum_list". This function takes in a single parameter and if it is a number, the function will simply return that number. However, if it is a list of numbers, it will return the sum of the numbers in that list. Recursion is designed so that if this list of numbers contains a nested list of numbers, the function will break up the list into smaller calculations.
This week's lab was based on tracing the Recursion process of a particular function. I received a mark of 1/2 because I missed the main focus of Recursion which is to break down the function as much as possible. The function was the following:

def ce(L):
     """(list of int) -> int
     """

   
     if isinstance(L, list):

        return sum([ce(x) for x in L])

     else:

        return 1

One of the tracing problems was the following:

Trace ce([15, 5, 3, 32, 19])

My first reaction was to take the sum of all the numbers in the list because according to the function definition, if the argument is a list of integers, it should return the sum of that list. However, I realized upon inspection, I misinterpreted the function definition. If each element in the list is not a list, it will return 1. Therefore, the solution to this problem would be the following:

ce([15, 5, 3, 32, 19]) -> sum([ce(x) for x in [15, 5, 3, 32, 19]])
                       -> sum([1, 1, 1, 1, 1])
                       -> 5

I believe tracing Recursion requires a little more practice and hopefully, I can master this practice in the coming days.

     Another important highlight to note is the term test. It consisted of three questions on Recursion and the construction of classes. It was a fair test and thanks to the extra practice I had with tracing Recursion, I was completely confident on what I wrote in each question. One of my friends (http://jinsooparkcsc148.blogspot.ca/) had problems with tracing Recursion, but I am sure he understands the main idea of it, which is to break down a function into smaller processes. Overall, this week has been the busiest so far this term and according to Professor Heap, he will teach how to code Recursion in the coming weeks.