This is my first SLOG post for my CSC148 course at the
University of Toronto. We are required to make weekly posts on topics we learned in class. This week’s topic is Object-Oriented Programing,
and I will be talking about inheritance and recursion, possibly two of the most
important features of object-oriented programming.
The concepts of inheritance and recursion are something that
I’ve been familiar with, ever since high school. I have never really appreciated
these two features much as I did until now, which is why I’ve decided to talk
about them in this weeks SLOG.
What is inheritance you might ask? For those that don’t know
inheritance is when an object or class is based on another
object or class, using the same implementation. In other words,
inheritance is what allows you to inherit stuff from other objects or classes. Recursion
on the other hand is used to define an object in terms of
itself.
When looking back at lasts week exercise, E1, it was clear
how important these concept are when writing the code for the exercise. The
inheritance feature came real handy when completing e1b.py. For the method play in class Dog, we had to inherit the
class Toy. Without
inheritance feature of object-oriented programming, I would have had to copy
and paste the coding making it longer, harder to read, and less efficient. Recursion
on the other had was more useful in e1a.py, where we had to take two parameters
x
and eps
,
and return the square root of
x
within an accuracy
of eps
. Recursion made it
easier, since I could use classes within itself. This made my life much easier
since I did not have to copy and paste the code over and over again to complete
the class.
Professor Heap made it pretty clear in class that we should
try to make our code efficient and as easy to read as possible. Without
inheritance and recursion, my coding would be extremely messy and hard to
understand. In order for my coding to work, I would have to continually copy
and paste code, which would be quite the hassle and would make the code very inefficient.
This copy and pasting of code would have also made my code extremely long,
which means that it would’ve taken much more time to write the code.
One of the challenges I faced with the E1 was trying to
remember everything from CSC108 course, as it’s been more than two years since
I took any computer science course. I had to re-familiarize myself with
Wingware and re-familiarize myself with computer programming in general. One of
the ways I overcame this problem was that I used YouTube to re-familiarize
myself with the python basics, such as loops, classes, and the basic built-in
functions of python.
I don't think you've understood what recursion is about. Look more carefully in your course material..
ReplyDeleteCheers,
a TA