03.10.2012 Views

API Design Matters Stonebraker and Seltzer - RabbitMQ

API Design Matters Stonebraker and Seltzer - RabbitMQ

API Design Matters Stonebraker and Seltzer - RabbitMQ

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

en)<br />

<strong>API</strong><br />

<strong>Design</strong> <strong>Matters</strong><br />

After more than 25 years as a software engineer, I still find<br />

myself underestimating the time it will take to complete<br />

a particular programming task. Sometimes, the resulting<br />

schedule slip is caused by my own shortcomings: as I dig<br />

into a problem, I simply discover that it is a lot harder<br />

than I initially thought, so the problem takes longer to<br />

solve—such is life as a programmer. Just as often I know<br />

exactly what I want to achieve <strong>and</strong> how to achieve it,<br />

but it still takes far longer than anticipated. When that<br />

happens, it is usually because I am struggling with an <strong>API</strong><br />

that seems to do its level best to throw rocks in my path<br />

<strong>and</strong> make my life difficult. What I find telling is that,<br />

after 25 years of progress in software engineering, this<br />

still happens. Worse, recent <strong>API</strong>s implemented in modern<br />

programming languages make the same mistakes as their<br />

two-decade-old counterparts written in C. There seems to<br />

be something elusive about <strong>API</strong> design that, despite many<br />

years of progress, we have yet to master.<br />

Good <strong>API</strong>s ArE HArd<br />

We all recognize a good <strong>API</strong> when we get to use one.<br />

Good <strong>API</strong>s are a joy to use. They work without friction<br />

more queue: www.acmqueue.com<br />

<strong>and</strong> almost disappear from sight: the right call for a<br />

particular job is available at just the right time, can be<br />

found <strong>and</strong> memorized easily, is well documented, has an<br />

interface that is intuitive to use, <strong>and</strong> deals correctly with<br />

boundary conditions.<br />

So, why are there so many bad <strong>API</strong>s around? The<br />

prime reason is that, for every way to design an <strong>API</strong><br />

correctly, there are usually dozens of ways to design it<br />

incorrectly. Simply put, it is very easy to create a bad <strong>API</strong><br />

<strong>and</strong> rather difficult to create a good one. Even minor<br />

<strong>and</strong> quite innocent design flaws have a tendency to get<br />

magnified out of all proportion because <strong>API</strong>s are provided<br />

once, but are called many times. If a design flaw results in<br />

awkward or inefficient code, the resulting problems show<br />

up at every point the <strong>API</strong> is called. In addition, separate<br />

design flaws that in isolation are minor can interact with<br />

each other in surprisingly damaging ways <strong>and</strong> quickly<br />

lead to a huge amount of collateral damage.<br />

BAd <strong>API</strong>s ArE EAsy<br />

Before I go on, let me show you by example how seemingly<br />

innocuous design choices can have far-reaching<br />

ACM QUEUE May/June 2007 25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!