This episode will explain different types of programming in terms that you will be familiar with and then relate everything to computer programming concepts.
You might be surprised that you already know how to program.
Programming is just the process of creating a set of instructions for a computer to follow. You already know how to follow instructions and give directions.
But have you ever followed instructions that no longer applied or left you wondering if you missed something? Maybe your directions said to turn left and there was nothing but a solid wall. As humans, we know how to stop following directions when they are obviously wrong. But computers will run right into that wall.
There are levels of programming and this episode explains three levels such as you might encounter when baking a cake. Programming is not as hard as you might think.
You can listen to the full episode or read the full transcript below.
Programming is just the process of creating a set of instructions for a computer to follow.
You already know how to follow instructions and even help another person when asked for directions. These instructions could help you navigate your way to your destination or give you the steps needed to bake a cake from scratch.
But have you ever followed instructions that no longer applied or left you wondering if you missed something? Maybe your directions said to turn left and there was nothing but a solid wall. As humans, we know how to stop following directions when they are obviously wrong.
Sometimes we get distracted and can end up in completely the wrong place even though there were multiple obvious clues that something wasn’t quite right.
A computer does not have our insight. Even a trained horse will sometimes refuse to obey instructions that it thinks would lead to danger. Computers will do exactly what we tell them to do and continue to follow our instructions until, well, that’s just it. There is no “until.” A computer will continue following instructions right up to the point when the power cord is ripped away.
Hold on there! I can hear you say. I can reboot my computer. I can press the reset switch and start it over. I don’t have to unplug it to recover from a mistake. That’s only because a programmer has already provided the computer with instructions to follow when certain finger twisting keys are pressed. The programmer has already provided instructions for what to do when the reset button is pressed. The computer is ALWAYS following instructions. That’s all it knows. It has no awareness or ability to reason on its own.
I mentioned that there are different types of programming. Let’s take the example of baking a cake.
Recipes have to be either written or spoken and that means there is a language involved. The directions could be in English or in Spanish or something else entirely. At first this might seem like just a matter of replacing each word from one language with its corresponding word from another language but it’s not always so simple.
I’m going to deviate for a moment here because I can’t think of a cake recipe that needs rice. But stay with me because this recipe calls for rice in our cake. Now in English, there is just one word for rice. But in other languages, there are separate and distinct words for rice depending on what state it is in. Still in the field? That’s one word. Prepared and ready to cook? That’s another word. Cooked already? You guessed it. That’s another word.
This means that the entire structure of the directions can change from one language to another. Just imagine for a moment if English had different words for an egg and the confusion that could arise if the recipe called for a freshly laid egg by accident!
Computer programming has different languages and this would be similar to how you could choose to write your programs in C++ or in C#. These are different programming languages that actually look a lot alike but are very different at times. Sort of like the difference between American and British English. Very similar but there are some gotchas too.
Before we go any further with the different type of programming, let’s first talk about why we need computer programming languages at all. I mean, we do just fine with English, or German, or any other spoken language, right? Why can’t computers just accept our instructions in our native language?
It comes down to complexity and precision. Human languages are EXTREMELY complex. During WW2, the American forces needed a way to communicate troop orders secretly so that other forces could not learn the plans. There were special machines that could scramble messages but these systems were susceptible to being read no matter how strongly they were scrambled. Did you know that The United States found that the native Navajo language was so complex that it was better than anything else? Nobody but another Navajo speaker could understand what was being said.
Languages would be boring if they weren’t so complex. Novels and our great stories would be bland and uninspiring if the languages of the world were simple.
So what about precision? Well, have you ever put together a large piece of furniture from IKEA? Each part is labeled and this helps but what really helps are the pictures. Imagine how thick the instruction booklets would be if there were no pictures for a 8 foot tall bookcase and entertainment center. Do you think you could follow instructions like that if they had to be written in just words? You could? Alright maybe you could. Now for the real test, do you think you could write those instructions yourself so that anybody else could understand them?
And this is just for a set of instructions that takes maybe 10 to 30 pictures to represent. Imagine scaling that to the scope of a modern computer application that has millions of instructions.
Alright, so back to the different types of programming and our cake that we are still trying to bake.
There are different levels of instructions that we need to consider. What do I mean by levels? Well, there’s a big difference between a frozen cake that just needs to be thawed properly vs. boxed cake ingredients that need 2 eggs and a quarter cup of cooking oil vs. a recipe showing you how to start from scratch with the individual ingredients like flour, sugar, and water.
When we’re giving instructions to another person, we have the ability to adapt our instructions to the level of understanding of the other person. We might be able to say, “Mix the dry ingredients” and then move on. But if the other person does not understand, then we need to drop down to a lower level and say “Measure and put the flour and sugar into a bowl and then stir it until well mixed.” And if the other person still does not understand, then we can sometimes lose our patience and say “Step back, turn left, open the lower cupboard door, take out the large bowl, no not that one, the other large bowl, okay, put it on the table”, you get the idea.
That last example is pretty low level, right? But computers sometimes need much, much lower level instructions than this.
Just take one part of that: “put it on the table”. Seems obvious, right? Imagine this was a robot that you were programming and the table was already full of ingredients. Would the robot know that it should make room on the table first? Not unless you told it to consider this.
A lot of people think programming involves a lot of math. Not really. What it really involves more than anything is remembering when to clean the table.
Programming languages also have levels.
Some languages are more similar to the “Mix the dry ingredients.” Some are like “Measure and put the flour and sugar into a bowl.” And some are like the “Step back, turn left.” variety.
What happens when you are baking a cake and the phone rings? Or even worse, what happens when you spill the batter on the floor? These are interruptions and exceptional cases and you know what? They all need to be considered. Remember that ability that computers have of restarting when you press a button? Well, that would be like knowing that you need to get out of the house as quick as possible if the oven catches the kitchen on fire.
Before we end, let’s talk about what types of instructions you can use when programming. I’m going to put these in simple terms that you can understand just like the cake example.
The first thing you can do is group instructions together so you can refer to them easier and be able to tell one set of instructions from another. We need to be able to give each group a name. That’s just like what a cook book does when it lists the instructions for baking a sponge cake vs. a sheet cake.
Then you need to be able to slightly modify a set of instructions for a specific case. Imagine how frustrated you would be with a cook book that listed a chocolate cake recipe then a chocolate cake with chocolate chips recipe then a chocolate cake with nuts recipe. Silly right? It’s the same recipe that’s just been slightly modified. You need a way to send some extra information with your instructions so that the basic set of instructions can be followed with your changes incorporated too.
You need to be able to reuse these instruction groups and have them build on one another. Baking a cake and cooking breakfast will probably both involve the set of instructions that describe how to take a spoon out of the drawer.
You need to be able to perform basic operations like addition. This gives you the ability to count and know when you have finally reached 3 cups of flour.
You need the ability to test and compare things. This will give you the ability to know when the table needs to be cleared and when it is already clear. There’s no point in clearing a table that is already empty so you don’t want to have to write instructions to always clear the table. You want to be able to make a decision and either clear the table or move on.
Speaking of moving on, you will need the ability to jump from one set of instructions to another or from one place in your set of instructions to another place. This gives you the ability to do the same things multiple times. If you have to add 3 cups of flour, you don’t want to have to repeat yourself 3 times. Just write the instructions to add 1 cup, check if you have added 3 yet, and if not, then go back again to the same point where you add 1 cup.
You need to be able to remember things. What were you doing again? Adding flour? That’s right! How many cups have you already added? You need some way to remember this or you won’t be very good at adding just 3 cups and your cake may end up more like a pancake.
And finally, you need to be able to combine things logically so for example you don’t try to pour the cake mix into the bowl until both the box AND the plastic bag have been opened. You want to be able to take the cake out of the oven when either the timer goes off OR the toothpick comes out clean.
Computer programming comes down to this. If you can bake a cake, then you can program.
While this is the essence of programming, there is actually a lot more to learn. But hopefully, I’ve given you enough real similarities to a simple task to encourage you to Take Up Code.