The first three
weeks of CSC148 introduced us to object-oriented programming, which is a style
of programming that centres on the creation of objects and classes. Objects are instances of classes in computer
memory; they are defined during program execution so that they can interact
with other objects in the program. Classes are blueprints of objects;
they define the attributes of objects and the operations that can be performed
on them. One of the greatest advantages of object-oriented
programming is that we can create our own classes. A reason for why creating classes is so advantageous is code reuse. If
we had to write two programs, one to perform linear algebraic operations on
vectors and another to determine the distance between two locations on a map,
then we can define a class Point and a class Vector that inherits from
class Point. Class Vector then has the same attributes and methods
of class Point. If we need to overwrite existing methods and write
new methods for class Vector, then we can. Code reuse is important
because it saves programmers from the need to rewrite the same code again and again.
Another result of creating our own classes is greater programming
clarity. Every class of objects has a set of methods for that class
of objects. This allows the full extent of operations for every object to
become clear to programmers. This is important because
programmers can then have an easier time deciding if they should use an
object from class A or an object from class B in their
programs. Therefore, for me, the ability to create our own classes of is
one of the greatest strengths of object-oriented programming; it allows for
both greater programming clarity and code reuse.
Nevertheless,
objected-oriented programming is not easy to pick-up because of my previous
programming experiences in CSC108. The primary focus of CSC108 was
procedural programming where we wrote a series of functions to complete tasks;
writing classes only received a small focus. My uneasiness with classes
became apparent when in our first lab, we wrote a program that counts the
number of times a specific word is repeated in a text file. I asked myself
what was the difficulty behind my understanding of classes and I eventually
discovered that it was the syntax. I usually forgot that we needed
to use ‘self’ when we were working with class attributes in the body of our
methods. This also happened in defining the parameters of the
methods. I forgot to use (self) there too. Eventually, I
overcame some of my apprehension with classes by gaining a better understanding
of the syntax. Since I only identified my difficulties by asking
myself questions, I will continue to ask myself more questions in the course to
overcome my future difficulties.