Object-oriented programming is confusing.
When I first learned programming (around Grade 6) I used Pascal and it complemented my thinking process of how a program should work: line by line. Procedural programming focusing on the ability to manipulate an output utilizing functions was much more coherent to me. Take a variable, do this to it. Then do this. Then do that. This type of programming also helped me debug code a lot easier. Set up a breakpoint, set up variable watches, and then go through line by line and immediately pinpoint where the code is messing up.
I was also taught computer-type mathematics at the same time - recursion algorithms, regular expressions, graph theory, basic boolean algebra, and LISP. These concepts reinforced the procedural thinking process - operations working on variables taken one at a time. None of this silly object business.
Then in Grade 10 they told me to learn Java and thus I approached it the Pascal way. Only to find out that it wouldn't work. Now functions and procedures are called "methods" and they only operate on certain types of things that you have to make yourself called "objects". And you have to define a pile of initialization code and work around a pile of exceptions.
What happened to all those nice "I can use this function on everything" programs?
With that in mind, I find that it's a lot easier to think about programs in terms of procedures. If thinking about an object is required, then it's about thinking of the procedures an object follows, not the attributes that an object contains and how to manipulate them. Learning to figure out what code should DO instead of what code should REPRESENT is quite a bit more important and really benefits me in terms of thinking of algorithms.
Now that I've learned Python, which has an even looser system of variable declaration and function formation, I'm finding myself very grateful that procedural programming has taught me how to think about coding in an object-based system. An object can easily be summarized as a series of procedures to work on variables that are assigned to it, making each a self-sufficient "program". The main program just tells the object program what to do.
A different perspective on object-oriented programming makes it a little less confusing.
There is a saying that "you can write FORTRAN in any language". Don't fall into that trap! There is more than one way to solve a problem, there is more than one way to describe a system, there is more than one programming lanugage and there is more than one programming paradigm. Being in university is your chance to broaden your horizons, expose yourself to different ways of seeing things. That will make you a better problem solver, trust me :) Patience young padawan.
ReplyDeletePS. I'm really surprised you think of LISP as procedural!!
Cheers,
a TA
LOL When I rant I tend to make lots of mistakes. Like saying LISP is procedural. LISP is functional, for sure.
DeleteI'm trying to take as many perspectives as possible in what I learn - but the better example of this would be my music. I listen to as many different genres as possible to get a sense of what works when I write and what doesn't.