For those who are reading this post, I have a confession to make. I admit that despite having considerable prior self-taught knowledge in programming (C++) before being offered a place at the University of Toronto, I have not been a fan of object-oriented programming (OOP) until last semester, where I learnt about it for the second time in CSC108H1. Maybe it was experience, maybe it was the lack of necessity, but the programs that I wrote before U of T, I wrote every single one of them with only loops and functions - no classes, no objects. Now that I have been, should I say, reintroduced to OOP, my previous programs are starting to look very disorganised and littered with multiple redundant variables and functions.
Here, I should outline 2 of the main benefits of using OOP in programming as a reminder to myself, and for those of you who are still in doubt of the strengths of OOP:
- Increased Modularity - modularity has recently become a norm in most programing languages nowadays following the increasing mainstream-ness of programming itself. While one might argue that too much modularity might result in the general reduction in competence amongst programmers as a result of the oversimplification (mostly due to the increasing availability of hefty libraries online) of the process of coding itself, I personally think that the benefits still provides more than enough justification for the heavy usage of the modular approach.
- Simplify the Variable Creation (and Naming) Process - the concept of creating objects out of classes is one that enables us to associate certain variables or attributes to objects. The same name can be assigned to different instance variables by stringing it to its object. So, for example, a variable name like 'player_score' can be assigned to two players, each of which is an instance of a class called player, as player1.player_score and player2.player_score. This allows for a greater degree of accuracy for the coder him/herself.
No comments:
Post a Comment