How Does Immutability - Computerphile Work?

A list is like a toy box, you can add or take out toys whenever you want. But an immutable list is like a sealed toy box, once it's closed, you can’t change what’s inside.

Like a Frozen Toy Box

Imagine your favorite toy box is full of blocks. If the box is sealed, and no one can open it, you can't add or remove any blocks. That's immutability, it's like a list that doesn’t let you change anything after it’s made.

Now imagine you have two sealed toy boxes: one has red blocks, and the other has blue blocks. If you want to make a new box with both colors, you can't just add to the old ones, you need to create a new box with all the blocks from both.

Why It Matters

This might seem silly, but in computer land, it helps everything run faster and stay clearer. Like when you're playing with blocks, knowing which boxes are sealed helps you know what's inside without opening them every time. A list is like a toy box, you can add or take out toys whenever you want. But an immutable list is like a sealed toy box, once it's closed, you can’t change what’s inside.

Like a Frozen Toy Box

Imagine your favorite toy box is full of blocks. If the box is sealed, and no one can open it, you can't add or remove any blocks. That's immutability, it's like a list that doesn’t let you change anything after it’s made.

Now imagine you have two sealed toy boxes: one has red blocks, and the other has blue blocks. If you want to make a new box with both colors, you can't just add to the old ones, you need to create a new box with all the blocks from both.

Take the quiz →

Examples

  1. A number that can't be changed, like a locked box.
  2. A variable in code that stays the same once set.
  3. Like a secret message that can’t be altered once written.

Ask a question

See also

Discussion

Recent activity