The word “program” can be traced back to the Greek words “pro” (before) and “graphein” (write). In other words, it was the act of writing something in advance, or ahead-of-time. Of course, 2000 years ago this was not used in reference to writing instructions for computers, but it still accurately describes what we mean when we say “computer programming” or just “programming.” When we “program” a computer we are writing instructions that we want the computer to follow, before it begins the process of following those instructions.
The process of a human writing computer code is analogous to one human giving instructions for another human to follow. A classic example of this comes to play in food-preparation recipes. A recipe for a meal can be boiled-down to a sequence of instructions that a human must follow very carefully, and in the correct order, in order to arrive at the desired goal: a delicious meal. As a rudimentary example, let’s use the “recipe” for making a peanut butter and jelly sandwich (yes, this still counts as a “delicious meal” :). Imagine you were teaching your friend, Ryan, to make a Pb&J who had never made one before. If you had to write down the steps, you’d probably tell him something such as:
In this case, you essentially just “programmed,” except instead of programming a computer, you programmed Ryan. You wrote down the instructions for creating a Pb&J in advance, and then gave these instructions to your programe. Writing computer code, or “programming” a computer, can be thought of in a similar way to giving instructions to another human being. There are obviously some differences, because a computer is a very different type of entity.
As you might expect, computers aren’t really designed to create Pb&J sandwiches. However if we were to attempt to communicate to a computer how to make one, we would have to be much more specific that we were to Ryan. This is because Ryan can use his intuition, creativity, context, memory, etc to extrapolate some of the things we say. For example, when we said:
“Get out two slices of bread, a jar of peanut-butter, and a jar of jelly”
Ryan already knows what peanut-butter is, what jelly is, what bread is, and where these ingredients are stored in the kitchen. He also uses his intuition to figure out what we mean by “Get out…”. He can infer that this probably means pull each out of the cabinet / fridge and place them on the counter top. If we were to program the computer (say, inside of some kind of robot) to make Pb&J’s, we need to have instructions with much greater detail. For example
I think you get the idea. Of course this is a made-up example, and you should not begin learning programming by trying to teach a robot to make sandwiches for you. I use this example to drive home the points that (A) programming a computer is analogous to teaching a human being a new task and (B) when programming a computer, we need to learn to be extremely verbose and detail-oriented.
Another thing to consider about computer programming is the language with which we tell a computer what to do. As with human language, there are many different languages we can use to communicate instructions. We can use English as I am using in this write-up, but there’s also a plethora of alternative written and spoken languages that humans can understand. Some of these languages have similar syntax and alphabet, such as Spanish compared to Portuguese. Others use different alphabets, such as Latin compared to Cantonese. Some of these languages are ancient, whereas some have emerged over only the past few hundred years.
In a similar sense, there is an abundance of computer language varieties, each with their pros/cons and differences/similarities. Whereas the four most popular human languages in the world are English, Mandarin, Hindi, and Spanish, some of the most commonly-used computer languages in the world are Java, Python, C, and Javascript. For the purpose of this series of lessons, we will be sticking mainly to Python as the language-of-choice. So what is Python? For that, continue on to the next lesson.