1.2. Steps and Sequence

To learn anything well, we should always be unashamed to ask even the most basic question. So, what is a computer program?

Okay, I get it. That sounds too easy. I can take a room full of random people and ask, what is a computer program? I will get answers because everybody kind of knows that…

A computer program is a way to tell a computer what to do.

That's true but useless. It doesn't help us here. Or I'll get…

A computer program is a list of instructions.

This is also true and a bit more specific but still not very helpful. What does this really mean? What kind of instructions would be in such a list? What do they look like? How do you tell a computer to do something and what can you actually tell it to do? Oh sure. It would be great if we could actually just talk to it but as you can guess, our instructions need to be a little more specific. So...

A computer program is a collection of instructions that can be executed by a computer to perform a specific task.

Now before I show you some, I will admit that if you take them one by one, the instructions we can use in a computer project program are going to seem a little simple, unremarkable, unimpressive and a bit dull because they're simple things like add one number to another number.

That's the kind of thing we can actually ask a computer to do. Add one number to another number, display the word “hello” on the screen, beep for one half of a second. These are specific self-contained and very small instructions.

Many people have heard this but they don't want to admit that the idea of computer a program just being a collection of teeny tiny instructions is satisfying. It doesn't feel like a good enough answer.

Here's what I mean. If you've ever tried one of these many, “learn to code interactively” programming tutorials on the web, they'll usually have you begin by typing some simple instructions.

Whether you're trying to learn JavaScript, Swift or Python, what they ask you to type will usually look something like this:

Image

Fig 1.2.1: Simple program Instruction

Fig 1.2.1 shows one instruction telling the computer to display some text on the screen. You can use this one instruction to make a program to display Hello, World! on the screen. That's a program that just does one very basic thing: to prove that it works.

So, you write this, learn how to run or execute your new computer program and you get your result! Then you wonder if you're supposed to feel a programmer now. But when you look at the kind of thing you actually like to do on your computer and yours does not feel like the same thing as this:

Image

Fig 1.2.2: A red ball challenge computer game

So, I forgive you for thinking, okay, I can understand how this “Hello, World” program happens but there's no way, this computer game is just a list of instructions like add one number to another number. But it is! It really is. As we'll see, all computer programs are constructed from multiple small specific individual instructions.

Think of a recipe in a cookbook because that's also a list of instructions. It's a series of steps to follow to make one dish and it doesn't matter if that recipe should be short and simple or long and difficult. They all come down to specific, well-defined instructions like add one-quarter teaspoon salt or heat oven to 220 degrees. By itself, as in programming, each individual step is kind of boring and looking at one instruction by itself tells us nothing.

One instruction in a recipe could be used to make a cake, but it could also be part of a huge multi-day preparation of a 12-course state banquet for a hundred people involving truffled quail jelly and live lobsters. In cooking and in programming if you want impressive complicated results, you will still use basic, simple instructions, you will just have a lot more of them.

When you understand this fact intellectually, there'll be no part of your brain thinking, “yup, I don't see how we get from hello world to hello world of Warcraft”. It's okay if that's not apparent yet. That's why we're doing this course. But we start simple. We have to start with the programming equivalent of how to boil an egg because even if it's unexciting, it's how we get the first ideas into our bones.