Information has a shape too
When you store things, what do you put them in? Sometimes a long line, sometimes a table split into cells, sometimes a branching shape. Even the same things become easy or hard to grab depending on where you put them. Information is the same. There is a shape to holding information, and we'll call that shape a container.
Same information, different shapes
Say you have the names of five friends.
How will you hold these names?
You could stand them in one long line,
or put them in a table split into cells,
or split them like branches from top to bottom
and hang them there.
The contents are the same.
But the shape they're held in is totally different.
That shape is what we call a container.
Hold the same names as a line, a table, then a branch. The contents stay the same, the shape changes.
Even as the shape changed,
the names inside stayed the same.
But each shape
probably felt a little different.
A line shows the order at a glance,
a table is good for pointing at one cell,
a branch shows what's above and below.
So then,
which shape should we pick?
A container that fits the job
You shouldn't use just any container.
First picture the job you want to do.
If you want to go through things in order,
holding them as a line is good.
If you want to find something by name right away,
holding them as a table is good.
If you want to tell who is under whom,
a branch fits well.
Even for the same information, by purpose
the fitting container changes.
Tap the job you want. The container that fits it best lights up and tells you why.
Each time you tapped a different job,
the glowing container changed.
There isn't one container that's the right answer;
what you want to do decides the answer.
If order matters, a line;
if fast finding matters, a table.
But there's one more thing.
A single container can't do every job
equally well.
Some fast, some slow
Say you picked one container.
That container does some actions very fast
and some actions quite slowly.
Think of a line.
Going through it from the front is fast.
But to squeeze a new name
into the middle of the line,
you have to push everything after it, so it's slow.
Each container has things it's good at
and things it's clumsy at.
Pick a container, then tap an action. In the same container, fast and slow actions split apart.
Even inside the same container,
fast tasks in green and
slow tasks in red split apart.
So when you pick a container,
look at what you'll do most often.
A container where your frequent task is fast,
that's the good choice.
Even for the same data, how you hold it
decides whether it's fast or slow.
A taste of the main containers
Let's take a small taste, just the names,
of containers we'll meet often.
The one that holds things in order like a line is an array,
the one that holds pairs with a name tag is a dictionary,
there's one you add to and take from at one end only,
one where, lined up, the first in is the first out,
and a branching shape that splits top to bottom.
For now just remember the names and the feel.
The details come one by one in later lessons.
Tap through the main containers. Each one shows a one-line intro and what it fits.
It's fine if the names feel a bit new.
That there are many kinds of containers,
that each one fits certain jobs,
just holding onto that is enough for now.
Now that we've had a taste,
let's go back to the start
and gather what we learned into one line.
Let's wrap up
Gathered on one line, it is this.
Holding information has a shape too, a container.
Even the same data can take a different holding shape,
like a line, a table, or a branch.
You pick a container to fit the job.
A container is fast at some tasks and slow at others.
So picking well makes a program faster.
Even for the same data, how you hold it
decides the speed; that's the heart of it.
Tap the key points in order to review. (information has a shape -> a container that fits the job -> fast and slow tasks -> a taste of containers)
Now you know information has a shape too.
You've gained a bit of an eye for picking containers.
In the next lesson we'll look closely
at the most basic container,
the array that holds things in order like a line.
Let's uncover together its fast secret
of numbering each spot and pulling one out.