Abstraction in programming
The post can show you an essential programming concept. Ready to get your feet wet?
Everything is an abstraction. What?
Simply, look at the globe in the image below. It isn’t a real planet, but represents one. It doesn’t contain all of the details of the real planet (it is missing clouds, for just one easy example of something missing). It also adds in political ideas with borders and names of countries and states.
The process that the globe has experienced is called abstraction.
This post goes into detail about abstraction, and how it can be applied to programming to make life much easier. It also contains the risks of using abstractions.
Difficulty: Beginner | Easy | Normal | Challenging
- None, but for practical purposes it would be useful to be able to produce a “Hello, World!” application in your chosen programming language
Abstraction: The process of removing unnecessary detail from a problem
Model: A simulation to reproduce the behaviour of a system
What is abstraction?
From a programmer’s viewpoint, abstraction is removing the unnecessary details from a problem.
From a user’s viewpoint, abstraction can be we don’t need to know all of the details about something to understand it (with some limits).
Being a pilot
Some people who fly a plane know everything about the internal working of the engine and plane as a whole. Right down to how the vehicle is manufactured.
You might be aware that a plane has a flight stick. This is much like a joystick; you point the plane in a direction and it goes in that direction.
Now what actually happens is when you point the plane in a direction, the flaps change to point the plane in a particular direction. You can think of this like making a paper airplane (where you can choose the direction of the plane using the flaps).
On a simple level a keyboard or computer controller allows us to interact with games and computer programs.
However, the computer stores your data and programs as 0’s and 1's.
But these are actually stored within your computer on transistors.
Now if you wanted to create a program on a series of transistors would be near impossible. There would be so much work in trying to get the computer to do anything you’d never get any real work done!
In order to make things easier your computer has a host of programs and things to help you program it. The Operating System, programs and IDEs that help you to program the computer. Such IDEs include Visual Studio, Xcode and IDLE move you away from having to manually change the voltages on transistors.
Abstractions allow us to look at problems and ignore unnecessary details. In computing this might mean that we want to take a person and create a representation of a person as simply their name and age (where name is represented by text — here a String, and a whole number — here an Integer)
more advanced uses in computing include computers using visual abstractions to identify images using machine learning.
Real problems solved with abstractions
Right-this is going to feel rather maths-based. Unfortunately many problems programmers give as examples of problems solved through abstractions are like this. This isn’t a problem, but many programmers would argue day-to-day this is not something they have to worry about or deal with.
If we want to use the Squareroot function of our programming language (in this case, Python)
We call this procedural abstraction. We assume that the function is produced and tested to give us the correct result.
The danger of abstraction
Life through a lens means that you don’t see the wide view of what is happening.
How do you know you have picked the right abstraction for any problem?
Have you identified and removed the right unnecessary details?
Applying these ideas to real-world problems may seem tricky at first. However, the “Hello,World!” application is a simple example of this. You can say this program is created to welcome a person to the world — but it is just printing a String to the screen, a mere abstraction of a greeting.
Want to get in contact? Try the link here: