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.
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.
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.
It's kinda like a modeling clay (or Playdoh) mold. You can meticulously sculpt a modeling clay figurine every time. Or you can make a mold for it and press the model clay into it. Using a mold you can quickly make multiple of the same base figurine and then make fine adjustments to each one from there.
Imagine you build a shelf for your toys. You draw a sketch that leaves exactly enough space for each toy, measure the size you need and start building.
But now you realize that you can also use the Shelf for something different if you remove the vertical spacers. Now you have a more general thing. You can put anything on it without having to redesign a new shelf each time.
This can even go deeper: One day you recognize that a shelf and a box are basicly the same thing (stuff for storing other stuff). So now you can few them as a storage. You do not care how it looks like, just what it can do. But down at the bottom it is still a shelf or a Box.
This also can have disadvantages: Each Storing container lets you access its contents, but while you can just pick the stuff from a shelf, you may have to empty the box to get to the toy at the bottom. From the outer persective this is not visible and may be difficult to track down. This is called a leaky abstraction.
Top comments (9)
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.
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.
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.
Beautiful explanation! Thank you so much! It really put a lot into perspective for me. I really appreciate it. :)
It's kinda like a modeling clay (or Playdoh) mold. You can meticulously sculpt a modeling clay figurine every time. Or you can make a mold for it and press the model clay into it. Using a mold you can quickly make multiple of the same base figurine and then make fine adjustments to each one from there.
I like this analogy a lot, quick and to the point. Thank you, Kasey. :)
Imagine you build a shelf for your toys. You draw a sketch that leaves exactly enough space for each toy, measure the size you need and start building.
But now you realize that you can also use the Shelf for something different if you remove the vertical spacers. Now you have a more general thing. You can put anything on it without having to redesign a new shelf each time.
This can even go deeper: One day you recognize that a shelf and a box are basicly the same thing (stuff for storing other stuff). So now you can few them as a storage. You do not care how it looks like, just what it can do. But down at the bottom it is still a shelf or a Box.
This also can have disadvantages: Each Storing container lets you access its contents, but while you can just pick the stuff from a shelf, you may have to empty the box to get to the toy at the bottom. From the outer persective this is not visible and may be difficult to track down. This is called a leaky abstraction.
You know when you press a button and it does something, but you don't know how it does it? That's abstraction
It's like super powers, you don't know how they work, but they are still awesome