Question:
Why can't I wrap my head around object oriented programming?
2013-02-25 02:14:33 UTC
Let me start off by saying that I want to be able to program 2D video games.

My first programming language was Blitz Basic (procedural). I read through the entire book called "Game Programming for Teens" to learn it. I believe that I had a very firm grasp of how programming worked, at least at a beginner level. When I wanted to expand my knowledge to be able draw tile-maps though, there were no tutorials out there for the language that I could fully understand. So I gave up on the language. That was a couple years ago.

Over those years I have tried C, C++, Javascript, and Actionscript 3. I got up to the object-oriented part of each respective book and quit each of them soon after. I like the idea of object-oriented programming, but the deeper subject matter of it just seems to quickly overwhelm me. It's not really even that I don't understand what inheritance or abstraction is (although I admittedly can't remember what abstraction is off the top of my head), I think it's that there's just so much going on that you have to remember and manage. It makes writing my own OOPs difficult because I have to know how everything I'm writing interacts with everything else. Procedural programming comes very naturally to me. Any new language I select comes very easily to me at this point up until the OOP part.

I don't really remember how much of C I learned, but I probably ditched it because I couldn't find good tutorials relating to 2D programming. They've all been fun to learn up until their OO concepts. I really like Actionscript 3, but the OO concepts just crush me. Maybe I just need to learn them slower and make sure I've mastered each concept before moving on. It just seems so complex though, and when I look at how easy procedural programming is it's hard not to ask myself if I'm ever going to understand OOP.

Your thought? Maybe some book/tutorial recommendations (even though I've viewed countless on Amazon)? I've been think about re-learning Javascript through Codecademy.com. Or maybe Python. I love the process of learning a new programming language, but my brain just can't seem to handle it at a certain point. Thank you for your help.
Three answers:
Chris
2013-02-25 02:40:14 UTC
Just for clarification, when you say JavaScript, do you mean Java?



Also, I love OOP because it makes complex programs easy to build. I used to write small games in AMOS Professional on an Amiga when I was young (also procedural) and when I first delved into Java, I was overwhelmed, too.



But it's not like everything interacts with everything else; what you should do is build your classes in a way that makes using them as simple as possible, like an upside down tree.

Taking the example of a tile map, the main game loop will call the screen's render method, which will call the current level's render method, which will call each tile's render method, which will draw its Sprite to the screen.

This is strictly one-way, top to bottom; if your calls are criss-crossing all over the place, you're doing it wrong.
Russel
2013-02-25 02:53:38 UTC
Hi, I use Python which many people say is a good language to learn OOP, although I myself am not yet proficient in OOP but can give you a few tips that I know worked for me.



1) Practice as much as you can what you're learning/reading even if you don't entirely understand it. Sometimes we try to grasp a thing completely before trying to put it to use, but I've found that it's the attempt to put something to use that helps you grasp it. Also it gets you familiar with all the parts of the system so when you're reading or thinking about it you can do so more fluently and gain comprehension much better.



2) Read other peoples source code. A nice easy site for this is bitbucket. Look for good programs in a language you are fluent in and read the source code line by line, even if it seems over your head, it's supposed to.



3) Don't give things only one try. I almost never understand anything worth understanding the first time round. I have no problem reading something through one day and then reading it again the next day, or even more. This applies to tip no. 2 also btw.



I used to like the clever approach to learning stuff and try to pick it up in a systematic manner and understand things completely first so as not to make mistakes (work it out on paper first so to speak). Since I've gotten into programming I've been forced to drop that idea. You learn best by doing and mucking up, and then learning something (just a little) from each mess up. Or I like to say use your fingers not your brain (not really though, should always use your brain but... you know what I mean :)
deonejuan
2013-02-25 04:31:05 UTC
I like java as it seems to always have an add-on to continue whatever I start. Perhaps you understand arrays?



int[] nums = new int[ 5 ] ;

nums[ 0 ] = 99;

nums[ 1 ] = 101;

nums[ 2 ] = 6666;

nums[ 3 ] = -33;

nums[ 4 ] = 5;



'nums' is the reference (the human label) that points to a location in computer RAM for an Object of type integers-array. To fetch or change any slot in the integers array we would use the bracket[ x ] indexer.



Objects are much the same way. Instead of the brackets[ x ] you use the dot-notation...

myCar.numofWheels;



The keyword 'new' is a verb...

Car myCar = new Car();

'new' invokes a special method upon the blueprint that describes Car. The blueprint is called a 'class'.



I really didn't understand Objects until I read in some textbook about an imaginary example. What if you had a class file describing a stopwatch graphic and everywhere you clicked on the desktop a 'new' stopwatch would spring to live and start spinning? One class file makes many stopwatch copies. Each of the copies are in computer memory and are independent of all the others. The stopwatch hands would be in various different spinning positions because they started with different mouseclick events.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...