Sunday, 15 February 2015

Object Oriented Programming - Week 6 of CSC148



Hi guys!

Object Oriented Programming (OOP) was a tough concept to learn at first. It made no sense and seemed useless. However, the assignments we’re given for the semester helped me see why OOP is useful. When we work on our assignments, designing new games each time and creating a new subclass for each game that is specific to the game while inheriting methods from a common parent class makes life much easier than having to do things (i.e. designing functions and attributes) separately and repeatedly for each game. So let’s explore the OOP concepts we’ve learned so far this semester: objects, abstract data types, methods, inheritance, and recursion.

Objects
Objects contain both information and behaviour. When working with Python, every value is an object with a specific memory address whose behaviour can be accessed using the dot (“.”) operator. So classes, subclasses, methods, and arguments are all objects in Python.

ADTs
ADTs or Abstract Data Types are not specific to any particular programming language which is why they’re so great. They specify what was meant to be stored and particular operations provided on the data.  Examples of ADTs we’ve used in class are stacks, and queues. You can use stacks and queues in real life and in other programming languages. They're not specific to Python which is why they're so useful.

Methods
Methods perform one of two major functions. They're functions that are attached to a class instance and compute and report property related to that instance. Or they change/mutate properties of the instance while using information from it to perform their operations. We also learned about special methods that, in Python, are inherited from the object type but can be overridden when wanted. A few of these methods are ‘__eq__’, ‘__str__’, ‘__repr__’, and ‘__init__'.

Inheritance
We also learned about inheritance in lectures. Inheritance is when one or more subclasses inherit methods and attributes from their parent class. These subclasses can then override and extend the methods initialized in the parent class to perform operations specific to their own needs and operations.

Recursion
Recently we learned about recursion where a function calls itself in its own body. We learned how to trace recursive functions and predict outcomes of specific recursive functions by analyzing the code. We also learned how to prove that a function carries out its task thoroughly for various depths of input (i.e. we proved that the function works for inputs of various depths).

That is a short summary of all the OOP concepts we’ve learned so far in CSC148. With this I'd like to conclude this post and wish you all a great reading week! 

Wednesday, 4 February 2015

Week 5 of CSC148

Hello guys! 

Last week we learned about Recursion in class. It is the process of calling a function in its own body. Why is Recursion important ? It's neater and more concise than simply using multiple loops. 

When we first encountered Recursion in the lectures, I found it to be confusing and complicated but when the professor went over it systematically, it started to make more sense. The great thing about the way we were taught Recursion was that before discussing it, our professor reviewed helpful functions and techniques used in recursive coding like list compressions and all() and zip(). Being aware of the various aspects used in recursive coding before learning about Recursion made it easier to scan through the code. 

Not only that, but the python visualizer has been a great help in explaining to me, step-by-step, how recursive code is processed and used by Python. When tackling a recursive function, I've realized that not being overwhelmed is the key to understanding the code body. And then tracing it step by step, by first using an object with a low depth and then working our way to a higher depth really helps one to understand how Recursion works. 

With enough practice, tracing recursive code has become easier. And for now, those are all my thoughts and experiences with recursive functions for now.
 

Sunday, 1 February 2015

Week 4 =)



Hi everyone!


As week four of CSC148 comes to an end, we were asked to express our opinions and feelings about how the first few weeks of the class went for us. So far, we’ve learned about various topics surrounding Object Oriented Programming in Python such as special methods, self, Abstract Data Types, inheritance, and recursion. The first few weeks of the course were a little bumpy for me, to say the least. I had a hard time with the first assignment and the first lab and I couldn’t seem to understand how to code for inheritance and I didn’t understand what the whole point of self was. 



As assignment one’s due date approached, I was forced to review the class notes and examples multiple times so I could understand how to tackle the assignment. The most confusing part about inheritance and classes was that I didn’t know what to initialize. The concept only became more complicated after the first lab when we just initialized the class and nothing else. I didn’t understand how one was supposed to know what to initialize and what not to initialize. However, I worked through the examples covered in class on the Python Visualizer and tried to follow the code. After doing this, the concept of initializing classes and inheritance started becoming clearer. 



I’m sure as I continue my journey as a budding Computer Scientist, I will come across many other difficult concepts and will have to learn to overcome them. And while I learn to overcome my difficulties with Python, I will keep you posted. Have a great week! =)