Thursday, 30 January 2014

SLOG # 2



   This week we discussed more about recursion in class. A recursive function is a function that can call itself during its execution when certain condition is met. The numbers of the Fibonacci sequence can be thought as a sequence of numbers that can be calculated recursively. Each Fibonacci number is the sum of the previous two numbers, except the first two numbers which equals to 0 and 1. With the help of programming, we too can easily find the Fibonacci numbers using recursion.


def fibonacci(n):
if n == 0 or n == 1:
    return n
elif n > 1:
    return fibonacci(n - 1) + fibonacci(n - 2)


  This function above is a simple example of recursion function that can calculate for the first few hundreds of Fibonacci numbers. Once the recursion reaches a stage of calculating two Fibonacci number when the maximum recursion depth is reached, python would automatically return a RuntimeError. Recursive function can raises errors unexpectedly if we don’t pay attention to what test cases our code can and cannot handle. 

   During the lab this week, we worked on inheritance, exception, and writing test cases using Unittest. On the day I had my lab, I took most of the time to evaluate the correctness of my code and writing test cases. Although I had a better understanding of how I can use unittest after the lab, I figured I have to start review and practice programming more often to catch up with the course.

Thursday, 23 January 2014

SLOG #1 - Object Oriented Programming:



   Object Oriented Programming (OOP) is a method of programming based on a hierarchy of classes that utilizes objects rather than just the functions and procedures. In terms of OOP, an “object” refers to a particular instance of a class. An object can call on functions or methods of the class the object is an instance of.  Using object oriented programming, coding repetition can be reduced. Rather than writing coding repetitively one object after another, a class can be created, and the instances can be used to store the values. This style of programming also makes the codes easier to maintain because changes can be made within the object’s class.
   So far for this week, we’ve focussed on stacks, raising exception, and especially inheritance. In object oriented programming, inheritance allows a class (base class) to transfer its attribute onto another class (subclass). In addition, a subclass can override data and methods from the base class. This feature allows programmers to extend or modify codes using the created subclass without changing the base class. For instance if I have already created a class A, then allow B to inherit from A allow B to gain access to any method that is in A that is not defined in B. If B contains any method that happens to share the same name with a method from A, then we consider B has overridden that method whether we want to extend on top of the original method or not. Using OOP creating a stack, or raising an exception can be achieved by writing their individual classes. This means inheritance would applicable once a base class is created as I have seen from my lectures.
   Overall, starting off a semester by learning about object oriented programming not only was it fun, but it also helped me to refresh my memory on the concepts I learn from csc108 while learning new concepts with respect to programming.

First Post



   Hi guys, this my first post on csc148 courSE LOG. I will document my experiences in computer science throughout the next few months. Also, I am looking forward to read and post up more interesting courSe LOGs (those that are made in the past and the ones that will soon be accessible) once I become more familiar with both the course material as well as using the blog itself.