DEV Community

Discussion on: Explain Abstractions like I'm five

Collapse
 
isaacdlyman profile image
Isaac Lyman

Imagine you want a sunny side up egg for breakfast. Your mommy or daddy needs to make it because you're not old enough to use the stove.

You say:

"Mommy/daddy: please take a small skillet from the cupboard above the sink. Place it on the stove over medium-low heat for three minutes. Add half a tablespoon of butter to the pan and wait for it to melt. Crack a raw egg and open it so that the edible portion of the egg goes into the warm pan, then throw the shell away. Get the lid that matches the skillet from the cupboard, moisten it, then use it to cover the skillet. Let the egg cook until a soft white membrane forms over the yolk, then immediately turn off the stove. Remove the lid, sprinkle a small amount of salt and pepper over the egg, then slide the egg onto a plate with a spatula and give me the plate."

If you have to say all of that every time you want an egg for breakfast, it won't be long before you give up on eggs.

Luckily, humans are very good with abstractions. So in real life, you may only have to explain how to make an egg once. Then you say: "This is how you make a sunny side up egg."

In the future, when you want an egg for breakfast, you only have to say, "Please make me a sunny side up egg." You don't have to deal with all the details. That's an abstraction.

In computer programs, almost everything is an abstraction. Functions, for example, are an abstraction because they take an algorithm and give it a single name so you can perform the algorithm without having to think about every instruction it contains. Large programs are built as layers upon layers of abstractions. Programming languages themselves are abstractions, because no CPU understands Ruby or JavaScript natively. Abstractions make it possible to do very complicated things by doing a series of very simple things, one at a time, then composing them all together.

Collapse
 
yokim profile image
Yokim Pillay

Beautiful explanation! Thank you so much! It really put a lot into perspective for me. I really appreciate it. :)

Collapse
 
_bigblind profile image
Frederik 👨‍💻➡️🌐 Creemers

Going from the 5-year-old to the programmer mindset, I think it beautifully illustrates abstractions with regards to communicating with the computer. You've defined how to do something before, so now you can ust say "do X".

You can also think of it as levels of detail. For example, when talking about seasoning the eggs, it's much more appropriate to say "put some pepper and salt on the eggs", then to say "from the spice rack, take the salt shaker. Holid it above the eggs so that the surface covered in holes is facing downwards, parallel with the bottom of the pan. Make a quick upward motion with your hand, followed by a quick downward motion. Verify that some salt has actually come out of the holes and landed on the eggs. Repeat this 3 times, moving your hand slightly across the surface of the eggs to distribute the salt".

Simplifying this to "put some salt on the eggs" shortens your explanation, but also has the advantage of not specifying all of the details, making it useful in more cituations. For example, imagine your salt shaker has bigger holes. With such a shaker, it might be better to hold it slightly angled, and tap the shaker lightly to make salt come out.

When you say "put some salt and pepper on the eggs", you rely on your mother having access to a salt shaker, and knowing how to use it, so you don't have to think about those boring details yourself, you just want your eggs seasoned.

Collapse
 
isaacdlyman profile image
Isaac Lyman

Yes! Abstractions on top of abstractions. Turtles all the way down. "Salt" in this case is sodium chloride, which is a molecule, and a molecule is a collection of atoms, and an atom is a collection of quarks, which are the binary code of the universe. And we don't even have to know that in order to recognize and use salt, because our senses have interpreted and abstracted it for us.

Human language itself is an abstraction. The word "salt" doesn't look or sound like actual salt. Yet we're able to use it as a signifier without confusion. Abstraction really is the basis of intelligence.