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

Prerequisites:

  • None, but for practical purposes it would be useful to be able to produce a “Hello, World!” application in your chosen programming language

Terminology

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).

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.

Image for post
Image for post

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.

Image for post
Image for post

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).

Image for post
Image for post

Computing abstractions

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.

Image for post
Image for post

But these are actually stored within your computer on transistors.

Image for post
Image for post

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.

Image for post
Image for post
An IDE

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.

Image for post
Image for post

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)

import Math
Math.sqrt(16)

We call this procedural abstraction. We assume that the function is produced and tested to give us the correct result.

Image for post
Image for post

Awesome!

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?

Conclusion…

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:

https://twitter.com/stevenpcurtis

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store