Sunday, 15 February 2015

SLOG: Week 6 Object Oriented Programming.

We're nearly halfway done the summer term and I feel like I have learned many important concepts, mainly something computer scientists call object oriented programming. This is single-handedly one of the most important and powerful tools in all of computer science that allows to do what we can do in modern programs today. To put it simply, it is the most fundamental aspect in coding and without it, you can't really accomplish much; similarly to how you can't do much with butter without the bread.

As it's name describes, the concept revolves around the idea of objects and that of course means it has certain attributes and behaviours. For example if we have an blue bird object, it could have attributes such as colour and behaviours such as flying or eating which we can translate into methods. This is essentially the basic idea behind it and despite being so simple, it can accomplish many tasks. When we create a representation of an object, we call it a class and by doing this, we can instantiate an instance of a class (create the object) as many times as we want and if one of the created objects were modified, only the one specifically modified would be affected. This allows, for example in a zombie shooter game, there could be hundreds of zombies instantiated from the same zombie class but if the player were to shoot one zombie, only that zombie would be damaged while the others would remain unchanged.

However what truly makes object oriented programming shine is the process of inheritance which brings object oriented programming to its full potential. Similarly to how you inherit genetics from your parents, classes can do so too except that they inherit everything from their parents not just specific features. This allows us to group objects with similar features up, creating a hierarchy and preventing a lot of repeated and unnecessary code from appearing.

For Example, if we were creating some hostile enemies in a game, our classes would look like:

Enemy (Parent):
Attributes: Health, Damage, Speed
Behaviour: Walk, Attack

Zombie (Subclass of Enemy):
Behaviour: Attack (Override), BadBreath

In the above example, we have a general parent class and then a more specific subclass. Our subclass which is called zombie, despite not having any new attributes attached to it not only inherited all the attributes of Enemy but its behaviour as well. As demonstrated, code is used more efficiently since we don't need to recopy any of our attributes that any Enemy should have into hostile creature classes that we make. Also we can even override methods from the parent class to make it fit the subclass more. For example an enemy could have an Attack method which simply damages targets at a range but clearly a zombie can't attack at a range (assuming he can only use his hands) and thus we can modify the Attack method and make it damage targets that are very close. Furthermore we could even add our own methods to our subclass such as BadBreath which can't be accessed by our parent class since in relation to children and parents, parents do not inherit genes from the children.

This makes object oriented programming one of the most useful tools in programming and when put together with inheritance, anything can be accomplished which is why I will be sure to try my best in honing my skills in this area.

Sunday, 8 February 2015

SLOG: Week 5

Last week we started learning about recursion and I found the concept to be relatively easy. The idea is that a function continuously calls upon itself which is a very powerful tool we can use in solving complex problems that we could normally not accomplish through writing simple python code. For example it could be used to count the total number of elements in a list or even a list of lists. Recursion is so powerful that many programmers today use it on a daily basis and I believe that if I can get a solid grasp on this topic, I will be very successful in my future programming career. Despite understanding the concept of recursion, I always have trouble coming up with the correct algorithm in which I can translate into python code for complicated recursive functions because it's pretty hard to think of what specific things I need the function to do each time it is called. To improve upon this I'm planning to practice tracing more recursive functions to the point where I can clearly visualize what each call will do without having to write it out.





On another note, we also had our first midterm this week which I felt I did a pretty good job on. However, I feel like I could have done better had I coded a bit more since I completely forgot what to put in methods that were meant to be abstract and overridden by subclasses. I now know that I should have wrote an exception or perhaps put pass instead of writing something that had no correlation to the question whatsoever. Another thing I should probably do next time is study a bit more since I ended up sleeping all night due to the fact that I was dead tired from staying up the previous night studying for a psychology midterm. 

Sunday, 1 February 2015

SLOG: Week 4

These first few weeks in CSC148 have been pretty hectic. Since the very first day of class, I noticed that the difficulty level of this course was exponentially greater than its predecessor CSC108 and through each lecture, the difficulty only gradually increased. In addition, the transition from having classes only three days a week to classes everyday only made it that much more difficult to adjust to the level of difficulty that this course had to offer. As a result I tried to review my notes everyday in order to understand the key concepts that were covered in lecture and to see how to apply them in future assignments/programs that I do.






Despite understanding the concepts, one of the main things I'm disappointed about are the quizzes. Although they were generally easy questions, I ended up doing pretty badly on them since my lab occurred at 9 am and I usually don't get enough sleep. As a result, I didn't read over the questions carefully enough and ended up writing a completely wrong answer. To improve upon this, I'm going to try to make a schedule to better manage my time and also to practice writing out code more so that I have an ample amount of time to finish the quizzes and check over my answers.