Stupid Question : What is an API ?

Discussion in 'Mac Programming' started by fab5freddy, Jul 28, 2009.

  1. macrumors 65816

    fab5freddy

    Joined:
    Jan 21, 2007
    Location:
    Heaven or Hell
    #1
    I have a kind of Newbie Question :

    What exactly is an API ?

    I am trying to learn some OO PHP and JavaScript
    and am trying to understand what an API is
    but am having a headache trying to figure it out!

    I have already googled it and don't understand most
    of the definitions i have found!

    Please Help a Newbie!
     
  2. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    It is an Application Programming Interface.

    Basically it is a way for a programmer to define an interface by exposing certain functions / classes / methods etc to other programmers so that they can interact with the application / library / operating system that the developer is making.
     
  3. macrumors regular

    Joined:
    Apr 7, 2004
    Location:
    Israel
    #3
    Ah, the lost art of explaining things clearly. That will give the OP an even bigger headache.

    OP:

    An API is the sum of the programming hooks a software library offers to programmers.
    If you used a graphics library, for instance, the API for that would be the various different functions that library allows you to use in it.

    Sometimes, API is also used in the singular, as in: one single function you can use in that library or system.

    This is a gross oversimplification but should be good enough.
     
  4. macrumors member

    Joined:
    Jan 11, 2009
    #4
    Once upon a time, everything was written in assembly and everybody had to look at every piece of code to know what was going on. When programs started getting bigger, that didn't work so well. In instead, programmers used a technique called modularization- they split the programs up into lots of little tiny pieces that have to talk to each other. That way, you only need to know 1) the way your little piece works and 2) the way other little pieces can talk to your piece.

    The Application Programming Interface is the list of ways that the program can communicate with other programs. It tells you *what* the program does so you don't need to know *how* it does it- you can just assume it's a little black box that works.

    Think of it like driving a car. You don't necessarily need to know what happens when you hit the accelerator, all you know is that applying pressure to it makes you go faster. "hit the accelerator = go faster" is the API while the actual details of increasing flow into the cylinder are implementation details.
     
  5. macrumors newbie

    Joined:
    Jul 21, 2008
    #5
    Very well explained... even I could understand!
     
  6. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #6
    A very simple example of a function from an API would be something like this:

    Code:
    SDL_BlitSurface(myGraphic, NULL, background, NULL);
    

    You can see (if you know what blit means) that this would put a graphic on a screen.

    What you don't see is the mess and tangle of code that makes this simple function possible. All you know about is that function to load images onto the screen. The above code example is using SDL. There are other API's such as Direct X or OpenGL.
     

Share This Page