seegongsik
Programming

What is code

Programming, coding: they sound hard and special. But what they really are is surprisingly simple: words that tell a computer what to do, in order. That's all.

01

Recipes and directions are code too

We actually already know what code is.
Think of the recipe on the back of an instant-noodle pack.
"Boil the water, add the noodles and the seasoning, wait 4 minutes 30 seconds."
A to-do list written in order: that's the essence of code.

Cooking ramen

  1. 1Boil 550ml of water
  2. 2Add the noodles and powder
  3. 3Wait 4 min 30 sec
  4. 4Turn off the heat

The way to a friend's place

  1. 1Go straight
  2. 2Turn left at the store
  3. 3Go 100 meters
  4. 4It's the second house

Code we use every day.

Instructions written in order to tell someone what to do: code is exactly that.
The only difference is that the one listening is a computer, not a person.

02

A computer reads from the top

A computer reads code from top to bottom, one line at a time.
Just as a person follows a recipe step by step, it goes very fast but always in order.
Press run below and the results appear one line at a time.

1Say hello
2Ask the name
3Say goodbye
Run it and the result shows here

It runs one line at a time.

One line has to finish before the next one starts.
Order is the flow, and this simple rule is the backbone of every program.

03

Change the order and the result changes

Why does "in order" matter so much?
Because changing the order changes the result.
"Put on your socks, then your shoes" and "put on your shoes, then your socks" are the same actions, yet the order alone makes a completely different result.

This order
1. Put on socks
2. Put on shoes
Dressed just right
Just swap the order
1. Put on shoes
2. Put on socks
It got weird

Same actions, different order.

Computers are the same.
Swap the order of "take the money" and "hand over the item," and you get a totally different result.
That's why, when you write code, you have to choose the order carefully.

04

A computer takes you literally

Ask a person to "tidy up a bit" and they'll figure out what to do.
A computer won't. It does only what you said, exactly as you said it.
There's no "roughly" or "use your judgment," so if you leave something out or say it wrong, it'll go ahead and do the wrong thing.

What I said:
Go forward 3 steps
It went exactly 3 steps
What I said:
Go forward (didn't say how many steps)
No stop command, so it keeps going

What I said versus what it did.

That might seem frustrating, but it's actually a big strength.
Because it does exactly what it's told, the same code always behaves the same way, which means you can rely on it.
In return, we have to give precise instructions.

05

Give a robot directions

Now it's your turn.
How many "forward one square" commands do you need to stack to get the robot to the flag?
Stack the commands and press run: with the right number it reaches the flag, and with too few it stops partway.

Press the buttons above to stack commands

Stack commands, then run.

What you just did is programming.
Lining up instructions in order and having the computer carry them out exactly.
In the next lesson, we'll see where the "values" these instructions work with are kept.

In one lineCode is words that tell a computer what to do, in order. Like a recipe, it's read from top to bottom, one line at a time, and since a computer does exactly what it's told, all we need to do is get the order right.
← Programming
Was this helpful? Support seegongsik