01. What is programming?
No code in this chapter. Before you write anything for a computer to run, it helps to know what you are actually doing when you write a program. The next few chapters build that understanding with only words, paper, and a pencil.
A program is a list of steps
A program is a list of steps for a computer to follow. The computer reads the steps in order, top to bottom, and does each one.
You already know how to write a list of steps. A recipe is a list of steps for a person:
1. Put two slices of bread in the toaster.
2. Push the lever down.
3. Wait two minutes.
4. Take the bread out.
5. Spread butter on the toast.
A program is the same idea, but the instructions are for a computer, not a person.
The computer is exactly literal
There is one giant difference between instructions for a person and instructions for a computer. A person fills in the gaps. If a recipe says put the bread in the toaster, you know which way up, how far in, and that the wrapper does not go in too.
A computer fills in nothing. It does exactly what you say, no more, no less. Forget to say take the wrapper off first and it will toast the wrapper.
That sounds annoying, and at first it is. It is also why computers can do things no person can: they never get tired, bored, or careless. They do the steps you wrote, the same way, every time.
When something goes wrong in a program, it is usually because the person writing it forgot a step or wrote one the computer took the wrong way. That is a bug. Bugs are not a sign you are bad at programming. Every programmer fixes bugs every day. It is part of the job, not a failure.
Look around the room you are in right now. Pick one device — a phone, a microwave, a game console, anything. Try to name three small steps it does that a person would never bother writing down because they would feel "obvious". (Example for a microwave: open the door, place the food inside, check that no metal is on the food, close the door, press start.)
What does code look like?
Code is just text in a file. Here is a tiny program written in Lua, the language you will learn in this book:
local name = "Keiko"
print("Hello, " .. name)
You are not expected to understand that yet — by the end of Chapter 11 you will read every word. The point now is that code is not a wall of symbols. It is plain text in short lines that follow one language's rules. Once you know the rules, the lines read like sentences.
What can you do with it?
Anything that involves following steps can be a program. A few examples you might find interesting:
- A game where the computer picks a secret number and you try to guess it.
- A text adventure where you walk through rooms and pick up items.
- A small Roblox experience where coins appear in the world and disappear when you walk into them.
You will build all three in this book. The first two run in a normal terminal window; the third runs inside Roblox Studio.
What this chapter wanted you to take away
- A program is a list of steps.
- The computer does exactly what you say.
- Bugs are normal. They are not a sign of failure.
- The rest of this book teaches you the steps a computer understands.
Homework
The homework for Part 1 is on paper — no computer yet. Grab a sheet and a pencil. The point is to practice writing instructions, not to write code.
Problem 1 — Spot the vague step
A person wrote these steps for "make a cup of tea":
1. Boil some water.
2. Get a tea bag.
3. Put it in a mug.
4. Make it the right strength.
5. Add milk if you want.
Three of those steps are too vague for a computer to follow as written. Write the three step numbers down and, for each one, explain in one sentence what the computer would not know how to do.
Problem 2 — Be the computer
Rewrite the instruction Tidy your room as a list of five
to ten specific steps. Imagine you are writing for someone who has never
seen your room. Each step has to be small enough that a careful person
could do it without asking a question.
Problem 3 — Where would it break?
A program for "make pancakes" includes this step:
Pour half of the bowl's contents into the pan.
If a friend doubled the recipe (so the bowl is twice as full), would this step still produce the right amount of pancake batter? Why or why not? Two or three sentences.
Challenge — The sandwich sheet
Write a list of six numbered steps for getting a sibling, parent, or friend to make you a peanut butter and jam sandwich. Write every step so specifically that the other person could not get it wrong even if they tried to take every step the silliest possible way ("but you did not say which side of the bread"). When you are done, hand the sheet to someone and ask them to follow it literally. See where it breaks.
Stuck or finished? Open the homework solutions page.