On the way to dinner tonight, my fiance asked me why there are so many different programming languages, and what the differences between them all are. While she has a firm grasp of technology, she is not an engineer, so I tried to figure out a way to explain the differences without getting too deep into the details. Hopefully this will be useful to other people, especially artists, designers, and producers in games who hear language names like C# and Objective C but have no understanding of what the differences mean.
A programming language is a series of rules and instructions for a computer processor to follow. To start an analogy, I will be the computer and you will be writing instructions for me. You decide that you want to tell me to go to the grocery store, get you a banana, and bring it home. To accomplish this, you get out a sheet of paper and write down the steps for me to follow on it. The instructions on this paper is programming code.
In video games, programming starts with a language called “Assembly.” With the advent of home video game consoles in the late ‘70s and early ‘80s, you had low cost machines with not very powerful processors for running instructions. You want to tell me to go to the grocery store, but I have a mind as simple as the Atari 2600. You will need to write very specific and simple instructions:
Step 1: Lift left leg.
Step 2: Move left leg forward.
Step 3: Place left leg down.
Step 4: Lift right leg.
Step 5: Move right leg forward.
Step 6: Place right leg down.
Step 7: Turn to the left slightly.
As you can imagine, this will get me somewhere. If you wrote it exactly correct, it will get me to the grocery store, get me to buy a banana, and get me home. The problem is this is very tedious and error prone. What if you miscounted the number of steps to take? When you give me this paper with these instructions and they are slightly off, I might walk into a car in the parking lot, attempt to buy a banana, fail, and then walk past my home on the way back. What if you decide that you want to send me somewhere else? You have to write down an entirely new set of instructions for walking me to the new place.
A few years ago, I started writing Atari 2600 games in my spare time for fun, in Assembly. As you can imagine, I made a lot of mistakes, and if I miscounted the number of instructions I was running my code would explode and I would get garbage on the screen instead of what I intended.
At this point, you are going to want to invent a new way to write these instructions, a new programming language. Up next is C, a procedural based programming language. Now you can turn these tedious instructions into something a little more manageable, it might look like this:
Step 1: Joe – Walk To – GroceryStore
Step 2: Joe – Buy Banana
Step 3: Joe – Walk To – Home
Of course, you need to now tell me what it means to walk to a place, and what it means to buy a banana. As I’m not slightly smarter than an Atari 2600, and even a little smarter than a NES, I can follow more complex rules without my brain exploding. So as part of writing this procedural based instruction set, you now need to tell me what it means to walk to a place, and what it means to buy a banana. You hand me another piece of paper with this set of instructions on it:
“Walk To” : Takes a Person and a Place, and moves the person to that place.
Turn Person to look at Place if they are not
While Person is not at Place, do the following: Have Person take a step towards Place
Of course now you need to tell me what it means to turn, and what it means to walk, and will keep defining the process into smaller and simpler steps until I understand everything.
Fantastic, now not only is your list of instructions on the piece of paper easier for you to write, you can even send me to new places without needing to tell me how to walk. As long as I have that piece of paper that tells me how to walk to a place, you can tell me to walk to anywhere with another set of simple instructions.
Unfortunately for the NES, C is a little too slow. Games written in C run much slower than those written in Assembly on the NES. In the analogy, imagine that every time I take a step I have to sit down, shuffle through all the papers to understand what it means to take a step. I’m walking so much slower than I did with the extremely specific Assembly instructions. Step. Look at instructions. Step. Look at instructions. This is a big driving force in deciding what language to use, sometimes you’re working with a slow idiot who can’t remember how to walk. Fortunately technology marches onwards, and I’m replaceable. You’re frustrated with slow NES Joe following C instructions slowly, and you hate writing the tedious Assembly instructions. Luckily a shipment of Sega Genesis Joes just arrived, and he’s smart enough to use the C instructions and take steps without looking at the paper every time, and can get you your banana pretty quickly.
Your next door neighbor comes over at this point, impressed with your ability to tell me to go buy bananas. He asks for a copy of your instructions so he can send his friend Steve to go buy apples.
OK this is great, you’ve got instructions for telling a person how to walk somewhere, but what happens if you decide to tell your dog to walk somewhere? A dog is not a person, your dog cannot follow people instructions. If you give him the slip of paper telling him to walk somewhere, he will just slobber on it.
This is where C++ comes in. C++ is an object based programming language. You are a very astute person, and have probably realized at this point that dogs and people both have legs, and both can technically walk. What if there was a way you could write instructions anything that could walk could follow?
Step 1: Joe – Walk To – Grocery Store
Step 2: Joe – Buy Banana
Step 3: Joe – Walk To – Home
Step 1: Dog – Walk To – Mailbox
Step 2: Dog – Bark
Step 3: Dog – Walk To – Home
At this point you realize you have a magic dog that can read, lucky you. Unfortunately the dog will not follow any instructions meant for people, so you can’t just give him what you wrote in C. You decide it’s time to move on, and invent C++, it’s like C, but better! You decide that, because people and dogs can both walk, you will call anything that can walk a “Walker”, and write some instructions that anything that can walk can follow.
“Walk To” takes a Walker and a Place, and moves the walker to the place.
Turn Walker to look at Place if they are not
While Walker is not at Place, do the following: Have Walker take a step towards Place
That looks pretty familiar, doesn’t it? Well, there is one hitch in this plan, when you give this piece of paper to the dog and to me, we are both going to stare at you. I don’t know what a Walker is, the dog does not know what a Walker is. You get out your pen again, and write this down:
Joe, you are a Person. A Person is a Walker, but better. You can buy bananas, and other Walkers cannot.
Dog, you are a Dog. A Dog is a Walker, but better. You can bark, and other walkers cannot.
Great, we are both on our way now. Look how much our process for writing instructions has progressed, you can tell anything that can walk to go anywhere!
You’re so excited about this, you run over to your neighbor’s house, who has been sending Steve to buy apples, and tell him about C++ and how you can control anything that walks. He looks at you and says he had to figure out the same thing, and invented Objective C.
So far you’ve probably figured out that another driving force for creating new languages is to make use of more powerful hardware to allow you to more easily write complex instructions. Another big reason so many languages exist is, in a pre-internet age, many people were solving the same problems at the same time. While C++ was being created at Bell labs in 1979, and named C++ in 1983, Objective C was created in 1983 at a company called Stepstone.
Hopefully that is a good start in explaining the differences in programming languages, and why so many exist, and how each one can serve a new and different purpose. Dozens of languages exist, each serve very different purposes.