Sunday, January 26, 2014

C'est un Objet

Speaking as a math student, sometimes in an attempt to precisely describe something professors tend to over-complicate it. Objects in programming are one of those things that is almost a trivially simple concept to explain, but is often obscured by complex language. So to prove that it is really not as complicated as it sounds, I decided to explain it to my 76 year old Grandmother. Here is the explanation:
Computers are idiots. Sure they can do things fast, but in order to get a computer to do something right, you have to sit down and give it incredibly precise instructions. Look at this FreeCell game you play. It's not like all these things just existed in the computer and a few keystrokes built the game, someone had to build it piece by piece, from telling it which cards can go on top of others, to the exact conditions when you win, and even things like what to do when you are holding the mouse button down and moving a card around. In order for this to not drive the poor programmer crazy, he would use something called an "Object". An object is exactly what it sounds like, it is a computer representation of some "object" that behaves like we expect it to. In the case of your FreeCell game, we can think of the card as an object. What a programmer can do is create a "Card" in the computer which would represent what we know of as a card. He would then tell the computer exactly what to do with the card, from it's value, to how it looks, to how it behaves when you click on it, as well as whether you can stack them on top of each other, and the conditions for winning. Simple attributes like the suit and value of the card would be stored as "variables", and complicated behaviours that the card can engage in are written as what we call "methods", which is just a fancy way of saying "stuff the card does".
Sure, that maybe isn't super precise, and being a university you would expect that the professor would teach you a 100% accurate model... however sometimes there is room for a bastardized explanation. Maybe preciseness can come after understanding.