Blog, Learn Tech Skills

Tech Term: Object-oriented programming

Object-orientation allows you to create objects within the world of your computer program that have specific and unique attributes and abilities.

When you think about programming languages the key thing to remember is that they are languages, just like human languages, and their purpose is to provide us, humans, with a way to communicate with them, the machines.

But since computers are extremely simple, programming languages also must be simple, and much of what we take for granted when speaking in our human languages must be made excruciatingly explicit.

Consider this situation: I have a computer program called pets in which I wish to have my dog Lola do doggy things like bark and fetch a stick.

Now, remember, the computer understands almost nothing until I explain it.

So, before I can tell the computer about my dog Lola and her fancy handshaking abilities, I have to explain to the computer what a dog is.

I would do this by creating the object Dog, and giving it certain attributes (name, breed, etc.) and certain abilities that are unique to Dogs (barking, fetching, etc).

In Ruby, one object-orientated programming language, the code might look like this:

class Dog
attr_accessor :name, :breed
def bark
puts "woof"

Now, with this code, I am able to create my dog, give her the name Lola, the breed Malti-Poo and make her bark:

mydog = = "Lola"
mydog.breed = "Malti-Poo"

When programming languages are not object-oriented then there are just objects and abilities, and no connection between the two. Meaning a dog can bark, but so could a blog post. The program has no way of knowing the difference between a dog and blog post.

If object-orientation makes perfect sense to you, that’s because we too are object-orientated; we understand that there are objects (dog, computer, boyfriend, tree) each with their own set of specific and unique attributes (breed, version, marriageability, deciduous or evergreen) and abilities (bark, program, kiss, defoliate).

And this is why Alan Kay’s creation of the first explicitly object-oriented programming language Smalltalk was so revolutionary: it brought computer programming one extremely important step closer to the human language.

Cocktail Party Fact

Ruby and Python, two very popular web programming languages are definitely object-oriented. And as of PHP v.5, PHP is also object oriented.

So the question remains: is JavaScript an object oriented programming language?

Apparently, that depends on how you define object orientation. Many people argue that because JavaScript does not support classes of object (as seen in the Ruby example above) it is not a truly object-oriented programming language.

Douglas Crockford, the programmer who created JSON, disagrees. He argues that JavaScript is one of the most grossly misunderstood programming languages and despite all the naysayers, is quite object-oriented!

What do you think?