A Recipe the Machine Follows
A program is a recipe for a very literal cook. Meet the algorithm, with no code in sight.
A quick note on how we teach here. You won't find equations or numbers in this series, and that is on purpose. The goal is understanding, not arithmetic, so every idea is explained in plain words and simple pictures. When you want the math later, the rest of Internals Decoded is ready for you.
Welcome back. In the first piece we met a kitchen helper that can do exactly what it is told, no more and no less. Then we saw how tiny switches hold all kinds of information, from a simple note to a whole photograph. Now we have the pieces. The helper has a pantry full of on and off switches that represent anything we can imagine. But a pantry, even one full of perfect ingredients, does not make dinner. The helper needs to know what to do with all those switches. It needs a recipe.
A program is nothing more than that recipe. It is a list of instructions written ahead of time that the computer follows step by step. Every app you open, every website you visit, every game you play is, underneath, a long and carefully written recipe that the machine obeys without question. If we can understand a recipe card, we can understand what a program really is.
A recipe card for a very literal cook
Imagine you need to teach someone to bake a cake, but this person has never stepped into a kitchen before. They do not know what flour looks like. They do not know what “mix” means. They have no common sense and no judgment. You cannot just say “make a cake.” You must write down every tiny step in order: open the cupboard, take out the bag labeled flour, scoop one cup, level it with the back of a knife, pour it into the big metal bowl, and so on. If you leave out a step, the cake will be a disaster. If you write the steps in the wrong order, the cake will also be a disaster. The helper will do exactly what you wrote, no matter how silly, because following instructions is all it knows. When a computer's recipe has a missing or misplaced step like this, programmers call it a bug.
A computer is the same kind of helper. Before it can do anything useful, someone has to write down a recipe that is just as precise. The recipe cannot assume the computer knows the difference between a photo and a song. Every small action must be spelled out. The computer will then carry out each instruction in turn, from the first line to the last, unless the recipe itself tells it to jump somewhere else. That is the whole secret. A program is a recipe card for a very literal cook.
More than just straight lines
At first glance, a recipe might look like a simple straight list. Do this. Then do that. Then do the next thing. But the most useful recipes include two extra powers. They can make choices, and they can repeat steps.
Think about a real kitchen recipe. It often says something like “if the butter is melted, add the sugar. Otherwise, keep warming.” That is a choice built into the instructions. The cook checks something, and the recipe branches off in one direction or another. A program can do the same. It can look at a switch that is on or off, compare two pieces of stored information, and decide which page of the recipe to follow next.
Real recipes also ask you to repeat something. “Stir until the batter is smooth” means keep stirring, check the batter, and if it is not smooth yet, stir again. A program can wrap a set of steps in a loop just like that, doing the same few instructions over and over until some condition is met. This tiny idea, repeating a handful of steps many times, is what lets a computer sort through a whole library of books or draw every leaf on a tree without a person having to write out each leaf one by one.
Choices and repeats, stacked together, are enough to build astonishingly rich things out of plain instructions. A video game feels alive not because the computer is thinking, but because the recipe keeps checking what the player presses and repeating little routines to update the screen. An invoice or a receipt that fills itself out on a website is not magic. Beneath it, a recipe is checking numbers, repeating rows, and deciding what appears where.
Seeing recipes everywhere
Now that you know the idea, you will start seeing recipes everywhere in the digital world, even though you cannot read the ingredients. When you tap an icon on your phone, you are handing a recipe to the kitchen helper. That recipe might be small and simple, or it might be made of thousands of smaller recipes that all call out to one another like a cookbook full of well thumbed pages. The helper, remember, does not understand what a message is or why you want to send it. It only knows that some switches must be rearranged in a particular order, exactly as the recipe demands.
Everything a computer does rests on this idea. A website that streams you a video? The recipe reads the chosen video from storage, breaks it into tiny pieces, and sends them across the network one after another, following a plan written long before you pressed play. A checkout page that will not let you continue until every box is filled? A recipe: check each box, and if one is empty, show the red warning. No thought. No feeling. Just a recipe, followed step by step.
Not every program today is only a hand-written recipe, though. Modern search engines, for example, also use systems that learned from examples to judge which pages best fit your question, as Google's guide to its ranking systems explains. That second way of making a machine smart is exactly where this series is heading.
The name for a precise set of steps
People who build software have a special word for a careful set of instructions that solves a problem. They call it an algorithm. It sounds fancy, and it can make people feel as if there is something mystical going on. But an algorithm is exactly what we have been describing. It is a clear recipe. A sequence of steps that says “do this, then if that, go here, otherwise repeat these three steps until the answer is clear.” Even the humblest kitchen recipe is an algorithm for making a cake, as long as it is spelled out with enough detail for a literal cook.
From now on, when you hear someone talk about algorithms, you can picture a recipe card in your mind. You will hear the word everywhere, from "the video app's algorithm" to "a learning algorithm". Even a machine that learns is running an algorithm: a fixed recipe, written by people, for how to learn from examples. We will meet that recipe later in this series. But at root, it stays a simple idea: a list of instructions, written by a person, for a machine that will follow them to the letter.
Where this is heading
We have now seen how to turn the world into switches and how to hand a recipe to a helper that reads those switches. Until now, a person had to think through every possible situation and write down every single step. That works wonderfully for counting money, filling out a form, or drawing a button on a screen. But what about recognizing a friend’s face in a photograph? Or deciding whether an email looks suspicious? Those problems are far too messy to capture in a handwritten recipe. There are no simple rules that can say “if a pixel, one of those tiny dots, is this color and that shape, then this is definitely your dog.”
That crack is where the whole idea of learning sneaks in. It begins with a simpler question: what is a pattern, really? You are about to step onto the path that leads from recipes to something that feels a lot more like learning.
Test yourself
Write a recipe a literal helper could follow for brushing your teeth. Where did you need a choice, and where did you need a repeat?
Answer: A recipe might go: pick up your toothbrush. If the bristles are dry, turn on the tap and wet them. Squeeze a small blob of toothpaste onto the bristles. Brush the outsides of your teeth, then the insides, then the tops. Keep brushing until the timer on your phone goes off. Rinse your mouth and the brush, turn off the tap, and put the brush back. The choice is "if the bristles are dry": the helper checks something and acts only when it is true. The repeat is "keep brushing until the timer goes off": the same small action again and again until a condition is met. Notice how much you had to spell out, like turning off the tap, that a person would never need to be told.
Next: What We Mean by a Pattern. It looks at the patterns hiding in the world around us, and why they matter for machines that do more than follow a fixed recipe.