seegongsik
Saved words
Programming

What is code, really?

Programming, coding. It looks hard and special, somehow. But what it really is is surprisingly simple. Telling a computer what to do, in order, that's all it is.

01

A recipe and directions are code too

What code is, in fact,
we already know.
Think of a recipe.
"Boil the water,
add the noodles,
wait three minutes."
A to-do list written in order.
This is 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

The code we use every day.

Instructions written in order,
telling someone what to do.
Code is the same.
It's just that the listener
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, in turn.
Like a person following a recipe
one step at a time.
Very fast,
but always in order.
Try pressing play.

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

It runs one line at a time.

It finishes one line
before moving to the next.
Order is the flow itself.
This simple rule
is the backbone of every program.

03

Change the order and the result changes

Why does "in order" matter?
Because changing the order
changes the result.
"Put on socks, then shoes"
versus "put on shoes, then socks."
The same actions,
just a different order,
yet completely different.

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.

A computer is the same.
Swap the order of "take the money"
and "give the goods,"
and you get a totally different result.
So when you write code,
you have to set the order carefully.

04

A computer does exactly as told

Tell a person "just tidy up a bit"
and they figure it out.
A computer doesn't.
It does only what it's told,
exactly as told.
There's no "sort of" or "use your judgment."
So if you leave something out or tell it wrong,
it does the wrong thing exactly.

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 you said versus what it did.

This looks frustrating,
but it's actually a big advantage.
Because it does exactly as told,
the same code
always behaves the same.
That means it's reliable.
In return, we have to tell it precisely.

05

Tell a robot the way

Now it's your turn.
To send the robot to the flag,
how should you tell it?
Stack the commands in order,
then press run.
Get the order right and it reaches the flag,
otherwise it stops somewhere odd.

Press the buttons above to stack commands

Stack the commands, then run.

What you just did
is programming itself.
Lining up commands in order,
and having the computer run them as is.
Next time we'll see
where the "values" these commands handle
are kept.

In one lineCode is telling a computer what to do, in order. Like a recipe, top to bottom, one line at a time. A computer does exactly as told, so all we have to do is set the order precisely.
Was this helpful? Support seegongsik
Programming