Friday, 27 February 2015

Week 7: uhhhhh

I would like my TA to grade my Object Oriented Programming summary in week 6.

Below is my revised version of week 6's impressions about Object Oriented Programming.

------------------------------------------------------------------------------------------------------------------

Object-oriented programming , as the name suggested, is a style of programming in which data and the operations are organized into objects. In other words, programmers focus on objects instead of the implementation details.

Here a few terms I had to define:

Object: A basic entity in Python that models a thing or concept in the real world, which contains attributes and behaviours.
In fact, every value in Python is an object, like str, int, list and dictionary.

Inheritance: A mechanism involves classes inherit (get) commonly used attributes and behaviours from other classes. A subclass (child) class, by default, inherits all the methods and attributes of the super (parent) class.

Class:  A template or blueprint for the objects of similar types.

My thoughts of OOP can be thought of as better organization and removing redundant code.

Methods are special functions written for a related class. This removes the concept of having a multitude of functions that each refer to some object. Thus, methods in classes are simply used to group related manipulators of objects and associate them with a class.

Inheritance was an extremely defining term in my mind. It allows me to reuse the same methods for inherited objects without having to encounter the problem of duplicate code.

In the example below, the use of inheritance from object oriented programming exemplifies the removal of having to initialize address and room as in class Townhall by inheriting the attributes from class House.




In addition, OOP removes the concept of having multiple functions referring to different objects by organizing them into classes and sub classes so that methods have a direct correlation to their class and subclasses. Professor Heap gave us a great example in class that demonstrated this concept. First he showed a few functions that were related to class point. Then he introduced another class called Heavypoint which had some duplicated code with the the parent class point. In the end, the professor cut down the duplicated areas and reduced the messy python code into classes followed by there methods and subclasses.

In summary, object oriented programming make modification to pre-existing code easy due to the ability to inherit methods and attributes from a parent class.

Week 6: Object Oriented Programming

Object-oriented programming , as the name suggested, is a style of programming in which data and the operations are organized into objects. In other words, programmers focus on objects instead of the implementation details.

Here a few terms I had to define:

Object: A basic entity in Python that models a thing or concept in the real world, which contains attributes and behaviours.
In fact, every value in Python is an object, like str, int, list and dictionary.

Inheritance: A mechanism involves classes inherit (get) commonly used attributes and behaviours from other classes. A subclass (child) class, by default, inherits all the methods and attributes of the super (parent) class.

Class:  A template or blueprint for the objects of similar types.

My thoughts of OOP can be thought of as better organization and removing redundant code.

Methods are special functions written for a related class. This removes the concept of having a multitude of functions that each refer to some object. Thus, methods in classes are simply used to group related manipulators of objects and associate them with a class.

Inheritance was an extremely defining term in my mind. It allows me to reuse the same methods for inherited objects without having to encounter the problem of duplicate code.

In the example below, the use of inheritance from object oriented programming exemplifies the removal of having to initialize address and room as in class Townhall by inheriting the attributes from class House.




In addition, OOP removes the concept of having multiple functions referring to different objects by organizing them into classes and sub classes so that methods have a direct correlation to their class and subclasses. Professor Heap gave us a great example in class that demonstrated this concept. First he showed a few functions that were related to class point. Then he introduced another class called Heavypoint which had some duplicated code with the the parent class point. In the end, the professor cut down the duplicated areas and reduced the messy python code into classes followed by there methods and subclasses.

In summary, object oriented programming make modification to pre-existing code easy due to the ability to inherit methods and attributes from a parent class.

Week 5: Recursion

ThisView blog is the fifth week of CSC148 and this week we covered recursion in our lecture. When Professor Heap first introduced the idea in class I was extremely happy to note that I had knowledge about this topic before hand. Factorials had been a common high school topic and I was easily able to translate the ideas into code. In my mind, recursion was simply a form of python script that called itself repeatably until it reaches the deepest element. Here is my implementation of factorial:


What I didn't know about recursion was that it is a extremely repetitive process. I noticed this after I can it through the python visualizer and noticed the amount of calls to line 2 and 4 that were made. Basically every time the function called itself, python had to determine whether the n-1 was equal to 1 or not. In addition, I gave myself a simple example and traced the code by hand when n = 4.


Summarizing my thoughts on tracing recursion, I found that I must first locate the recursive function and then use this code and apply it to each element of the object. Then making my way to unravel each of the calls to the lowest element. 

During the lab, I found that my understanding of recursion made it easy to do the lab material and quiz as I only thought of the questions presented as an onion that has multiple layers, slowly unwrapping until I reached the core.

I also found this video extremely helpful with my understanding of recursion:

https://www.youtube.com/watch?v=s12IdMeVpw0


Week 4: Yet Another Week

This is the fourth week of CSC148 and I feel relatively confident about the course material that we have been doing. I found that reading the course notes about inheritance and ADT very easy as it mostly required just reading the material and understanding the concepts of data representing and removing excessive code.

For inheritance, I found a really good example on David Liu's website (http://www.cs.toronto.edu/~liudavid/csc148/week2/inheritance.html) that allowed me to understand the material really well. Basically, I didn't understand how to carry over methods over to another subclass. However, this example on the webpage shed light on my confusion.

To use inheritance, I noticed that you have to include the parent class name,"House", in the declaration of the subclass. Also to carry over information of methods in from parent classes, I would simply write the parent class method preceded by the Parent class name(refer to line 3 in screen shot).

ADT was very easy to understand as it only required me to do a thorough reading of the course notes posted on the website.