Hey there, I'm known as GR and this is the start of my blog. I'm mainly starting this blog because it is an assignment, but feel free to read on if you find the above topic interesting.
A note: I do have previous experience with other languages like Java, C# and Visual Basic, and this course is rather like a refresher.
Object Oriented Programming...
This week, my lecture section was given an introduction to Object Oriented Programming (OOP). What is OOP? Of course, it means using objects in programming - well that makes sense (not really). I will give you a brief definition of what an object in programming is. An object is something that has related states and behaviors. What does this mean? Instead of giving a technical definition, I will give you an example of what an object might look like using a real-life application. Suppose that we have a bicycle. Some features of the bicycle include the ability to ride it, turning the front wheel to go left or right, variable speeds, etc. Some attributes that the bicycle include pedals for our feet to push against to move the bicycle, gears to assist us when going uphill or simply to gain speed, and the type of seat on the bicycle. I'm sure that you have a basic understanding of what a bicycle is; if not, there is a search engine called Google if you want more information!
Given my bicycle example, we can represent a bicycle as a class in an object oriented programming language. Classes are essentially objects, which have related states and behaviors, as stated previously. The features of the bicycle in my real-life example can be seen as methods or functions while the attributes are similar to instance variables of a Bicycle class. For example, one feature of a real bicycle is to turn the wheel left or right. If we introduce an instance variable that keeps track of the direction of a Bicycle object's "wheel", we can make a function that would assign 'left' or 'right' to an instance variable. In other words, we are setting a behavior of the Bicycle object. One attribute of a real bicycle could be the gear that its on. In a Bicycle class, an instance variable called 'gear' which stores the gear number can be used (perhaps 1 can be the lowest, 6 being the highest). When we set what the gear shift should be on (e.g. by assigning an integer by initializing a Bicycle object), we are setting a state of the bicycle class.
An Interesting Issue....
In CSC148, we learn OOP using Python. Python lacks the ability to encapsulate objects, fields, functions or methods. When you are encapsulating an object, you are essentially preventing access from other developers from accessing specific fields from outside a given class. Since Python doesn't have that ability, developers use conventions to notify that specific methods or instance variables shouldn't be touched. For example, instance variable names are led with an underscore before the intended name of a variable (e.g. self._gear, assuming we are talking about my Bicycle example). I had a small quarrel with the instructor because he claims that the Python programming language is completely Object Oriented (OO). As I have mentioned, Python lacks effectiveness to encapsulate objects or fields. If I were to create a class in Java which is OO, for example, and I wanted to create an Application Programming Interface (API) for some program for a developer, I want to be able to block access a few sensitive features of the program. Java has a keyword called private, and when you use this keyword prior to declaring a field, class or method, then it would ensure that its only accessible within the class and nowhere else. In Python, in an initialization method of a class, for example, you could only state a convention that only notifies other developers not to touch a certain field or method (underscore, followed by the field or method name). Python does not have a private keyword, and anything that is meant to be private can be touched. I proposed that Python is a hybrid between a functional and OO paradigm. At the end, he concluded that because Python's creators call it object oriented, then it must mean that it is.I was not satisfied with the answer, and I will continue to learn more about the Python language to uncover the answer for myself.
Sorting and Efficiency...
The next topic I want to talk about is about types of sorting and efficiency of algorithms. Simple sorting algorithms include bubble sort, insertion sort, and selection sort. In most cases, they are used to sort a list or lists of integers in ascending or descending order. An algorithm as simple as bubble sort is usually avoided when sorting a list of integers. This is because of the number of steps that it needs to take to sort a list of integers. Bubble sort continuously compares neighboring elements to see which one has a greater value, then swaps the two values depending on what kind of order the list needs to be in. The problem with this is that there are too many loops and comparisons being made, and it makes this algorithm inefficient. As you move on to a more complex algorithm such as insertion sort, the number of comparisons and loops made are reduced, which makes the task of sorting a list of integers faster, or rather, more efficient.
Recursion...
I want to briefly talk about recursion, which is also what I learned this week. In a nut-shell, recursion is when you call a function or a method inside itself. Most of the time, it is used to modify the values of parameters of a method passed into the function or method under certain conditions to get a desired result. Examples include adding integers using binary operations, or computing the factorial of a natural number. Recursion when used correctly can be used to significantly reduce the amount of coding required for a method when used correctly. It's rarely used by developers due to the complexity of coming up with ways to use them.
Final thoughts...
I really hope that I get to learn more about algorithms in CSC148. I will end my post here, and looking back at this, it's much longer than I intended it to be. The SLOGs for this week from other students seem to be centered around their feelings towards OOP while I did get a bit technical. After reading a few, I see that they also find OOP a clean-cut concept - quite easy to understand. If you have any questions about OOP or if you have suggestions about this post or blog, feel free to drop a comment below and I will answer them whenever I can. Bye for now!