Live data from Hacker News

The Worst API Ever Made?

mollyrocket.com

41–50 of 82 posts

Re: The Worst API Ever Made?

#41

"ALWAYS start by writing some code as if you were a user trying to do the thing that the API is supposed to do." It still amazes me how many times junior devs ignore this. They will spend a lot of time walking through the UX scenarios, mocking it up, etc. But when designing the API layer, they just start creating end points instead of focusing on the "DX" scenarios (developer experience, not theirs, but devs using th…

Designing decent APIs is a good use case for TDD. You start writing what makes sense from the client/problem domain perspective.

Writing code from the outside in. It's more iterative, experimental than TDD.

TDD is fine when you have a pretty good idea of what you're doing. Alas, most of the time, I'm just winging it.

Re: The Worst API Ever Made?

#42
I had amazing "fun" with Amazon's marketplace API. Highlights include: - rejection without error messages - multiple hours before the successful call showed up as successful - broken XML schemas along with conflicting versioning and

My favorite: - error messages from the API asking me to call customer service to perform that action.

Re: The Worst API Ever Made?

#43

Earlier quoted context omitted.

> What is the system supposed to do here? There are a million possibilities… No, there are two: You dump old data or you dump new data. Everything else should be up to the user code. It's really not as difficult as you are making it out to be. There's certainly no excuse for a ridiculous API as described in the article.

Huh? If you dump data you miss events. Imagine if Process Monitor decided to suddenly dump half of the system calls it monitored. Wouldn't that be ridiculous? For a general event-tracing system, there have to be more options provided. Maybe it wouldn't matter so much for context-switching per se, but for a ton of other types of events you really need to track each and every event.

> Huh? If you dump data you miss events. Imagine if Process Monitor decided to suddenly dump half of the system calls it monitored. Wouldn't that be ridiculous?

All sorts of systems have worked like this in the past (search for "ring buffer overwrite"). If you can't assume unlimited storage, you have to make a decision whether it's more important to have the latest data, dropping older samples, or whether it's more important to maintain the range of history by lowering precision (e.g. overwriting every other sample).

> but for a ton of other types of events you really need to track each and every event.

If you really need this, you have to change the design to keep up with event generation. That's outside the scope of a low-level kernel API where performance and stability trump a desire for data.

Re: The Worst API Ever Made?

#44
I offer a simple API decision which has condemned generations of programmers to useless toil. The decision in .Net to not map database NULL to programming language null. Perhaps there was some higher level philosophical distinction being drawn which mere mortals are not capable of understanding.

Re: The Worst API Ever Made?

#45

I had amazing "fun" with Amazon's marketplace API. Highlights include: - rejection without error messages - multiple hours before the successful call showed up as successful - broken XML schemas along with conflicting versioning and My favorite: - error messages from the API asking me to call customer service to perform that action.

According to Eric S. Raymond's version of the Jargon File, people used to joke that MS-DOS system calls delivered "same-day service." Now that we're living in the future, that joke has become literally true.

Re: The Worst API Ever Made?

#46
Poster has not worked very deeply with Win32, is unaware of its conventions. Film at 11.

For example:

> Yes, that’s right, every user of the Event Tracing for Windows API has to do the arithmetic and layout of the packed structure format themselves.

These represent very common idioms in Windows. One common idiom is about binary compatibility. Microsoft can change the length of the structure in a future rev of the SDK. Old callers can still work because they are specifying sizes and offsets - the library can look at these and know what to do. The other common idiom (very common in the NT kernel for example) is similar to what C99 introduced for structures with variable-length members, something C definitely didn't do for you and even today with it standardized still gets pretty clumsy.

The author lost all credibility when he wrote this:

> StringCbCopy((LPSTR)((char * )pSessionProperties + pSessionProperties->LoggerNameOffset), sizeof(KERNEL_LOGGER_NAME), KERNEL_LOGGER_NAME);

Why on earth would you say (LPSTR)(char * ) ? That is literally saying (char * ) (char * ).

To me a "bad" API enters into questions like:

* How does it handle errors? Consistency is good. Swallowing them to the caller is bad.

* Does it give the caller the right level of detail about what is going on? It's especially common for it to be a black box and completely fail under some condition that the author did not envision. Some kind of escape hook that exposes implementation details makes library maintanence difficult but sometimes it's needed.

I haven't looked too deeply at etw but I don't suspect it fails at these. Maybe it errs too much on one extreme on the 2nd bullet.

Re: The Worst API Ever Made?

#47
To be fair -- I am certainly not the only one that opened that page scared of seeing my own name. :-)

>> It’s a great time in the history of computing to be writing an article about bad APIs (which is another way of saying it’s a terrible time to actually have to program for a living).

It is hard to make good APIs. And for complex subjects it is probably impossible without iterating.

But you would think the guys that did the 2nd generation of VMS were smarter and more experienced than me? But OK, there weren't much event driven programming in VMS, I assume.

My vote for worst API I ever read:

I remember reading the "Inside Macintosh" (pre Mac OS X) about simple file IO and it took me multiple readings to realize that you just set some of the parameters to get all the different functionality... (The rewrite of the Inside books were really good.)

Re: The Worst API Ever Made?

#48
post #11
post #6

Can anyone recommend any resources about API design?

For a very deep, thorough and painful treatment instead of feel-good books, read "Practical API Design" by Jaroslav Tulach. Yes, it's Java, but it exemplifies the fundamental tradeoff that the feel-good books ignore: the more powerful you make your API for users, the less potential for evolution and long-term maintenance your API retains.

That is on my queue of books to buy. [Which is below my queue of books to read].

So shouldn't there be a way to balance these requirements?

It seems like we've ignored the ability to batch jobs, do async tasks etc. It sucks... but an API is out of my control.

Re: The Worst API Ever Made?

#49

Poster has not worked very deeply with Win32, is unaware of its conventions. Film at 11. For example: > Yes, that’s right, every user of the Event Tracing for Windows API has to do the arithmetic and layout of the packed structure format themselves. These represent very common idioms in Windows. One common idiom is about binary compatibility. Microsoft can change the length of the structure in a future rev of the SDK…

Ha, was my first thought as well: you could write this same article about essentially every aspect of the Win32 API.

Re: The Worst API Ever Made?

#50

Another "fun" API is the one from MUMPS (matrix processing stuff) in Fortran. See http://mumps.enseeiht.fr/doc/userguide_4.10.0.pdf , for example page 10. It has lot of numbered "ICNTL" (input control) variables as well as named struct fields, and some of those struct fields are only valid if, for example ICNTL(26) has the values 0, 1 or 2. ICNTL is actually an array with 40 elements, though "only" 1-33 are currently…

Wonder what it is about the name MUMPS that makes software called that so terrible...
Post reply on HN