The API: Developers’ Toolkits

You may have read of programmers using an APIApplication programmers interface – and wondered just what it is. The importance of APIs in developing applications of all types cannot be overstated. Without them, we would not have the computing systems – including mobile ones – that we know and use daily.

As I noted in the CPU article, the central processor of a computer can only do one thing at a time. It can do them extremely rapidly, 1 GHz (gigahertz) is one billion times per second, so a 4 GHz CPU will be able to processes 4 billion simple operations every second – and you can multiply that by the number of cores.

As noted in that article, what it does is extremely simple:

The instructions are pretty simplistic:

  • load a value from memory to an internal data register
  • move a value from one register to another
  • write a value from a register to memory
  • perform one arithmetic operation on values in two registers
  • perform one logical operation on values in 1 or 2 registers
  • test and branch

So to do anything complex, such as sending some simple text to a printer, requires an enormous number of steps – or instructions.

Higher level languages

Another way of making life easier for the programmer was the invention of higher level languages. This way we do not have to program in the ultra-simplistic, baby-step instructions known to the CPU – called machine code. Rather we can write something like:

a <= 2 * b^4;

or:

favorite_poet <= "Walt Whitman"

In the examples “a” and “b” and “favorite_poet” are computer variables (memory locations that can hold various values), and “<=” represents the assignment operator. So we are assigning the value of “2 x (b to the 4th power)” to the variable named “a” – etc. It is like the M+ key on a calculator. It stores the computed value into the variable to be used later.

These statements will be translated, or compiled, into the appropriate machine code by a program called a compiler. Each of these simple statements represents tens of machine code instructions. This is not only way more compact, but much easier to read.

Note how a programming language creates a higher level of abstraction by having more abstract symbols represent a collection of machine instructions. This lets us think in terms of the conceptual operations we wish to perform.

Functions to the rescue

The first step to solving the complexity issue was the concept of the function, or subroutine, or procedure. This was a set of code that you could write once, then use it again and again by calling it, usually sending it parameters, a set of values it is to work with. A procedure call might look something like this:

                 DisplayVideo(MyNewestVid, jpeg);

Functions can be be written by the programmer in order to replicate and common action in a standardized manner, simplifying future work. They can also be provided by the langue or by the operating system.

Operating System

The operating system (OS) is the base program, usually specified by the device manufacturer (although in many cases it can be changed by the end user). It provides the programmer with a set of functions that will perform higher level tasks, particularly those that interact with various hardware parts of the system: Screen, Keyboard, Wifi, Printers, USB ports, etc.

API

API stands for Application Programming Interface. It takes the abstraction level several steps higher. Here a system developer will create a set of very high level functions to do common, complex actions.

By abstracting the underlying implementation and only exposing objects or actions the developer needs, an API simplifies programming. [Wikipedia]

Most complex tasks have an API to support them. There are video APIs, Windows APIs, etc. If, as a programmer, you want to program the opening of a new window, you do not have to deal with all the extraordinarily complex code for making a visual display on a monitor. You call the windows routine that will create if for you with a size, locations, and a set of features, There are calls to set any toolbars, menus, colors, tabs…

The “PI” portion of API signifies the interface provided by the tool to the underlying system. That is, the interface is the set of functions that the developer can use to perform the operations that he or she wants to do, within the range of services of that particular API. So, if you want to get your iPhone’s current location, you use the appropriate call from Apple’s LocationKit and it will return to you the longitude and latitude coordinates. If you want to set the user’s target location, then you make different call sending the coordinates.

They include all these and more:

  • Open a window
  • Send something to a printer
  • Display photo
  • Generate and display 2D or 3D graphics
  • Communicate directly with a GPU
  • Get user interaction from a controller
  • View live video from a camera
  • Perform standard mathematical transformations
  • Send files over the internet
  • Communicate via a cellular connection
  • Get movement data from phone sensors
  • Save and access health data

Every function call

The importance of the API cannot be overstated.

Each one serves several purposes.

  1. First and foremost,  All the hard work is done for you! The programming underneath an API, the operations that it actually performs for the program, have all been worked on by specialist engineers and (hopefully) fully debugged.
  2. Actions have been accelerated for efficiency of operation to a degree that most individual programmers would have neither the skill nor the time to do.
  3. Programming of actions is standardized so that all programmers will be using the same protocols when writing their code. This makes it easier for several people to work on the same code base. Also it is easier to debug the application program.

The first item is particularly important when dealing with exceptionally complicated tasks, such as AI applications. Apple’s new ARKit is one of the best examples of this. Here it makes easy the use of surface detection, light source detection and other extremely difficult tasks.

 


If you appreciate this work

Then please check out my short fiction anthologies.

(Both available in both Amazon and iBooks stores.)

50CentFlash.com


View on Amazon
View iBooks Store


“They build up and then the surprise at the end turns things over.”  Ãsa S.
“The writing of short stories has been a lost art, but is making a timely reemergence. Jaan Seunnasepp delivers an enjoyable experience. Well before anyone noticed I was mentally lost in the moment.” Andrew

 


 

.

 

 

 

 

 

 

 

Advertisements