|
Authored by: Anonymous on Tuesday, May 01 2012 @ 06:08 PM EDT |
An API is just a set of rules about how programs interact with each other. Most
of the confusion is either deliberate water-muddying by people with a stake in
this, or people who confuse implementations with the idea of the API itself,
which is abstract.
I mean, the idea to have 3-prong electrical outlets is abstract, but there are a
lot of them in every US house. You can describe the interface on paper, saying
that it supplies 60 Hz, 120 V AC and this is where the hot, neutral & ground
prongs go. Or you can make an actual outlet and let people plug things in. The
idea of having prongs so far apart, of a certain size, out of wires of at least
a certain rating that takes electricity at 120 V AC/60 Hz in a certain way is an
interface for electronics, just as an API is an interface for programs. Anyone
can copy that arrangement, and indeed they must if they plan to plug things in
without needing an electrician for every device.
This only provides constraints, though. Knowing how the plug has to be shaped
doesn't tell you how to supply electricity to the wall outlet. The API is just
an interface for the program. So it's not really a blueprint. It only
specifies the interface. The documentation might go into more detail, but it
doesn't have to tell you how it provides the services it does. In fact, it
probably *shouldn't*, so that people don't rely upon implementation details, for
example the fact that you happen to use a stable sort when an unstable one would
be just as good. That would prevent you from replacing it with a
faster-on-average, unstable sort later without breaking their program, which
relied on details you wanted to reserve the right to change.
And yes, that's the whole point of APIs: to make changes easier. You define
interfaces between the programs which help isolate the impact of changes and
thereby contain buggy behavior. It's not perfect, but it prevents you from
having to care about any changes on the other side of the interface if you're
doing things correctly. That is, I don't have to care about how the power
company sends power to my electrical plug. They do their part, I do mine. I
don't have to change the wiring in my computer or my lamp whenever they do
something at the power plant. But in a badly written program? I just might
have to do the equivalent, and that really, really stinks.
Explanation of stable/unstable sorting algorithms:
https://en.wikipedia.org/wiki/Sorting_algorithm#Stability[ Reply to This | Parent | # ]
|
|
|
|
|