Thoughts on Software and Technology

Code as Language: Object-Orientation for the Complete Novice

This morning I sat on a conference call with the managers and bigwigs from a company I’m doing some programming work for. It was a progress update and when it came to me, I gave what I thought was a normal update. Something like:

… we’re pretty close to having the object model developed and have been focusing on a user-based view of what the code needs to do and how users use it to…

There was a polite pause, then I was asked the following question:

What is an object model?

This was hard. Suddenly, I was trying to describe object-oriented programming to the complete novice- to a non-programmer. I tried a couple times, and kept using programming language to describe it- which didn’t help because the person was not a programmer.

Toward the end of my tap dance, someone else on the call tried to help by saying something like “objects are like nouns, and they have these attributes and you can call the nouns methods.” It was only slightly better than the way I described it, actually- but the man was on the spot and came to my rescue. Still, I thought as he said that that it was a decent start, so I thought I’d flesh it out.

Code as Language

I started thinking more and more about an object as a noun. It is. If I have an object (you’ll hear the term ‘class’) that means I have a thing.1 Say my object is a car. That’s a noun. Now, just like all nouns, we can modify that. I can have a red car or a blue car. I can have a 4-wheel drive Subaru or a diesel VW Jetta. All of those other things are adjectives. Nouns have adjectives, and objects have attributes- but those are just adjectives. So we can have the following:

myCar = Car :color=>"red", :drive_type=>"two-wheel",
   :fuel=>"diesel", :model=>"Jetta"

That really just means myCar is a “red, two wheel drive, diesel Jetta.” We’re really just building a description of a noun using adjectives.

But we can also use verbs and adverbs. A verb equivalent is a function or a method. Just like in language, verbs are action words. We can use my car noun by making it drive:

myCar.Drive :speed=>"fast", :style=>"reckless"

Forgiving my unfortunate driving style, we’re just saying “Drive my red, two-wheel drive, diesel Jetta fast and recklessly”

The fundamental thing with a language is that you can string nouns, verbs and all together to create sentences, and sentences together to create paragraphs. Furthermore, with sentences, you can describe things that are not in that sentence: “Then he did that thing he does.” “He” is something that was defined somewhere else, maybe as “that guy who wrote the weird article on code as language.” When you string all of this together, you get something that was never in existence before- like this blog post. Similarly, when you string the nouns (objects), verbs (methods), and adjectives (attributes) of code together, you get something that was never in existence before: Software.

It’s no mistake that the thing one uses to create software is called “a language.” It is a language. To the non-programmer, it often seems like something mythical or magical, or at least little more than gobbledygook, but it’s nothing more than we’ve been doing for our entire lives. We’re using discrete words to create sentences and paragraphs- the compiler does the rest.

If you know how to speak, if you know how to read, you already know how to code, because using language is just coding a thought into speech so that the human compiler can translate it back into human thought.

This is just a morning thought that I found interesting. It’s not perfect, but an analogy never has to be. It’s good enough. I think I now have a better way now to explain an “object model” to a non-programmer. It’s a fleshing out of the nouns- who the actors are, what they look like, how they act- and the verbs- what the actors might do. I haven’t written the actual novel yet, but I have a rough sketch. That’s an object model: It’s the outline of a document that I haven’t really written yet.


No Comment

I've turned off comments on this blog. You can read all about that decision on Google+. I'm available at Google+ and Twitter for continued communication.
  1. as this is very basic, I won’t get into an instance versus a class []

Comments are closed.

Powered by WordPress | Designed by Elegant Themes