DEV Community

LM
LM

Posted on

The Art of Abstraction

Welcome!

Abstraction, what is it? How does it work? How do I balance a checkbook? How is abstraction the backbone of all computer programming? All but one of these questions will be answered in this blog post!

What is it: Abstraction refers to the process of taking big ideas and representing them in smaller, more digestible pieces of information. We see this in the process of making a "variable". Consider the code below:

let myGroceryList = ['apples', 'bananas', 'coconuts', 'strawberries'];
Enter fullscreen mode Exit fullscreen mode

This array of foods makes up the grocery list of a rather passionate fruit enthusiast! This fruit fan, let's call them Momo, can try to remember each item on his grocery list, or he can let the variable myGroceryList equal an array of list items:

['apples', 'bananas', 'coconuts', 'strawberries'];
Enter fullscreen mode Exit fullscreen mode

Right now, Momo only has 4 items on his grocery list. But let's say he was feeling particularly fruity one day, and decided to buy 20 different fruits. The myGroceryList variable would be far too large to just remember. What if Momo wanted to keep track of how many items were on his list? What if Momo wanted to add, change, or remove items from his list? What if Momo wanted to not only keep track of his own list, but also all the lists of his eccentric friends?

How Does it Work: To find out how many item are in his grocery list, Momo could access the length of his grocery list. He could then assign the length of his list, to yet another variable!

let myGroceryList = ['apples', 'bananas', 'coconuts', 'strawberries'];

let listLength = myGroceryList.length;

// => "myGroceryList" has 4 items, "myGroceryList.length" returns that length (4), 
// => we then assign that '4' to the listLength variable.

Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
cadienvan profile image
Michael Di Prisco

Hi @shokuninja and thank you for your first post.

May I ask you to clarify where the abstraction is here? I get the concept but I don't see any abstraction at all and that could be misleading for someone approaching your article.

Could you explain it a little further?

Thank you again,
Michael.

Collapse
 
shokuninja profile image
LM

Hi Michael, thank you for your comment!
Sorry if any part of this was misleading. To tell the truth, these blog posts are homework assignments for me and I didn't anticipate anyone actually reading them.

As for what the abstraction is, I was referring to the process of taking large ideas and referencing them with smaller, more manageable pieces of data. A variable for example. In the post, the variable myGroceryList was an abstract reference to the array ['apples', 'bananas', 'coconuts', 'strawberries']. More specifically it was "Data Abstraction". Now with this variable, which is an abstraction of an array, we can move this entire array around by just moving the variable. Variables are abstractions of simple values. Functions are abstractions of simple code. When I presented this to my class, I mentioned how even a word like "apple" is an abstraction of our understanding of this natural phenomenon we've come to designate as the "apple". And how doing so allows us to communicate how we want our apples to be made, observed, changed, or removed. Similarly, with abstraction in programming, when we take a variable, anytime we create, read, update, or delete that variable, those effects can be applied to the value it is an abstract reference to. Same with functions. This is how I visualize programming working, also language itself for that matter.

I'm about to present the blog I just posted to my class.
I hope this helps! Let me know if you have any other questions.

Collapse
 
cadienvan profile image
Michael Di Prisco

That answers my question way better, nice job!