Thursday, 22 January 2015

SLOG WEEK 3: Why Geeks Should Write

I have never written any type of Blogs before, yet alone Slogs, but I will attempt to my best ability. I will start with a few stipulations for the reader. Firstly, criticize me all you want. Please ensure the criticism is constructive to enable me to further improve any future Slogs. Secondly, feel free to give me feedback on ideas or concepts I mention. Lastly, I will attempt to tackle any concerns or questions you may have immediately or on the following scheduled Slog. Thank you in advance.
                I will begin by being honest. I haven’t been enrolled in any computer science course since last winter. That is almost a year with no computer science! Consequently, I had a lot of reviewing to do. Unfortunately, I did not attend the ‘ramp-up’ sessions provided by my TAs and professors. I knew that if I was to attend, I would be able to recall many of the findings I already discovered in previous computer science courses. However, life always get in your way of planned events, my absence from the ramp-up session was one of those cases. Although I did not attend this helpful session, I did manage to dedicate my own time to remembering and relearning the fundamentals that I have had in the past. How am I doing so far? Good or Bad? You will notice that I will take this Slog very seriously. When I attempt things, I always try to attempt them to my fullest ability. So let’s begin attempting this slog to the fullest ability by describing some issues I have discovered right away with the direction of this course.
                I find the professor, Danny Heap, a very informative individual. However, I always find a particular frustration, one that I have found in past computer science classes, which is the material in class, lab, and most importantly assignments almost don’t line up. I understand that in class we get the foundation. The lab we try to elaborate on it. And finally, in the assignment we try to go above and beyond. But my problem is that I do not see the follow chart from point A to point B to point C.  I understand that we are supposed to build our own intuition of what to do next based on the resources we have. But a little nudge in the right direction would not hurt, because it will assist the understanding of the actual material. To elaborate, it will help with the understanding of the key question “why” is it that we do this. Why do we do that rather than this?
                Anyways, that was maybe a little venting done by me, but now let’s gets to the actual computer science part! Objects are the main concern for the last two weeks. I did have a few confusions initially regarding objects; however, it seems that now I have a better understanding of them. I will try to explain those understandings. The first confusion I had with objects is why do we define certain methods that raise exceptions? Please refer to week 2 materials, more specifically the shape.py, square.py, and triangle.py. If you refer to shape.py you see that it has a draw function that raises an exception. This shape.py is a parent class of a sub class of square and triangle. Furthermore, square and triangle class have their own draw method. So my initial confusion was ‘why is it that we need to even include a draw method in the parent class if we:
                a) don’t inherit it in the sub-class, and
                b) we override it using a new draw method in the sub-class
The short but confusing answer is as follows:
The shape class, which is our parent class, captures all possible methods that one would like to do execute if they had a shape. For example, area would be a method that is applicable to all types of shapes. However, the shape class, yet again which is a parent class, does not capture which shape goes into it. It says that yes all shapes can have an area calculate upon them; however, by raising an exception we force the user to go to a sub-class, such as square or triangle, to actually calculate the according area formula. Because imagine that we had a shape class that does calculate area, then every time a new instance is created the area method would also have to capture which shape its dealing and then apply a different area calculation, BECAUSE NOT ALL SHAPES HAVE THE SAME AREA FORMULA. Therefore, we force the user to go through a sub-class to calculate area because the sub-class would have the right associated formula for that shape.  In conclusion, parent class tells us what is possible; however, the child-class helps us to differentiate how to execute this possibility depending on the child-class.
Not to brag, but a pretty good epiphany if you ask me. Now I want to talk about a new idea that professor Heap barely scratched the surface too – recursion. I think I get the idea of recursion, but in order to demonstrate it I will write you an example of exactly when it should be used and why. For starters recursion is used to take a big problem, separate it into similar but smaller problems, repeat these steps till we have a the most basic problem and execute that. While doing all that, we are literally calling the function on itself to keep breaking it to smaller problems. Now for my example, let’s assume that we want to know the bloodtype of everyone in the Canada. Writing a function that would go through each individual and record it is time consuming and most likely prone to error. So ah! Recursion must be able to assist us! So we start with what our first problem is which is Canada. We call a formula on it which sees if the inputted parameter is the most basic one, record the blood type, if it is not the case that it is the most basic one then call the same formula on it again. So Canada is the entered parameter, but Canada is a list of provinces. So we call the formula again on each province. Let us work with Ontario. The formula is called on Ontario, which is now our entered parameter, and yet again we see that Ontario is a list of regions. The same thing happens till we see that regions are a list of cities. We do this till the very basic problem. I think that is the hardest part: identifying the most basic problem. In our case it would be each person’s blood type. So getting back to recursion we would be calling the function over and over again till it hits our functions initial if statement which is if the unit is the most basic record the blood type. So we would be going from countryà provincesà regionsà cities à….  à individuals. As soon as we hit individual the function fulfills its purpose and exists that recursion formula and goes to the outer one. So for example if the function keeps going till it hits individuals and those individuals were in the city of Toronto for the region gta, then it will go to missauga in the region of gta. Then it will finish all the recursion problems in the GTA, and then it will exist central Ontario region and go to another region to it has literarly finished everything and recorded everything and existed to the point of Canada.
                I know it is very confusing, it is even more confusing to explain, but if you have a better way to word it please feel to reply!

I think this it for me today. Need to focus on something other than computer science… o how about philosophy courses – more specifically logic courses…. O wait.. that is not much different from what I have been doing so far! I want to mention this paper should display a perfect example of why Geeks like me should code J Have an awesome day guys!