Sunday, February 2, 2014

Recursion

The main focus of this week's lab was on recursion. As a math student, I have had some previous experience with recursions in the context of mathematics when dealing with recursive formulas for sums and integration of trig functions. In general, recursion is a process that repeat its itself until a terminating condition or the base case is reached. (Base case as in the base 'formula/function' that does not require recursion).  In the CSC148 lectures, we mostly talk about recursive functions, which are functions in python that calls on itself in its function body. Personally, the key in getting the hang of recursive functions is to carefully trace the examples that Professor Heap has given in class and draw arrows to see at what point of the function we are at. By manually tracing the recursive process, though it may be slow at first, one's mind would start to get used to the repetition and see how it reaches the base case every time a function is ran. Once, it was clear how recursion works, I began to see how it can save lines and lines of code when programming something that requires a repetitive process. However, after lectures when I looked over some of the examples the prof provided during class, these functions can be solved with an iterative solution as well. For example, on the function which checks depth of a list using while loops as well. So I was wondering if there are any preferred methods when one encounters a problem where the iterative method and the recursive method uses the same amount of lines. After some mild research, it can be said that iteration is a type of method that processes a problem repeatedly until it is done while recursion continuously breaks a problem into smaller/simpler pieces until a base case is reached. Thus, when dealing with something that is like a "tree" with a base case in the middle like the turtle example which the Prof has shown, it would be more natural to apply recursion. To conclude, the introduction to recursion in programming has now equipped me with another tool, of which I can apply to solve real life problems, namely, the assignment that is due in two weeks.

Wednesday, January 22, 2014

Object Oriented Programming

The main focus of the past 2 weeks of class had been on object oriented programming with an emphasis on class and its methods. As a student that comes from CSC108 where the topics have been briefly mentioned in class, I was able to gain a more in-depth understanding on these concepts. In lectures, we were given examples such as the class called Point, and through the creation of its properties and methods, it gives a clear demonstration as to how Classes should be made, when to make it, and how to manipulate it to the programmer's needs. Furthermore, the main ideology that was conveyed in class while programming was the mentality in being "lazy", meaning that one should be mindful in avoiding codes that are redundant or inefficient. The two concepts that was given to the class encompassing this ideology were list comprehensions and recursion. Despite how each of these are not heavily covered, but we can see through the usages of them in simple examples how they were able to reduce long lines of code to something as short as a return statement. In general, the past few lectures were focused on establishing the basic concepts and right mindset to object oriented programming through straightforward examples, and they were most certainly interesting and helpful.