in reply to API complexity measures

are there any objective complexity measures for APIs

No, pretty much all of them are arbitrary to one degree or another. I think complexity is a really hard thing to measure for APIs. For instance a complex problem domain will necessitate a complex API and that is a good thing. IMO, a simple API over a complex problem domain very rarely works. It is either not powerful enough, because the compromises the author had to make for the sake of simplicity removed too many features/options. Or it is actually more complex because the author applied their own personal world-view/metaphor-model to the problem domain and you have to understand that before you can even think about using the API itself.

Personally I have always been a fan of consistency being a good way to manage complexity in APIs. A few years ago I got a book called Reusable Software : The Base Object-Oriented Component Libraries by Bertrand Meyer off of eBay. It sat on my shelf for a while until I found myself needing to write a large-ish set of libraries for $work, and not having any clue how to approach it. The book has lots of really good advice, but the thing that stuck with me the most was the idea of using consistency as a way of managing complexity. Not only consistency in class, method and variable names, but consistency in abstractions as well. Meaning that similar concepts should be broken down in similar ways and provide similar features.

A side effect of consistency is also that it can breed habitual behavior. Around the same time I read The Humane Interface by Jef Raskin and The Invisible Computer by Donald Norman, neither of which are about APIs, but whose deeper messages can be applied to API design. The core ideas I took away from them was that a good interface is one whose use can become habitual, thereby moving from a conscious act to a (partially) subconscious act. This is not to be mistaken for "intuitive" which basically means "well it makes sense to me, what are you so stupid that you don't get this". To me a habitual API is one where after using it for a while it becomes possible to make educated guesses and have them be correct a fair portion of the time.

-stvn

Replies are listed 'Best First'.
Re^2: API complexity measures
by Your Mother (Archbishop) on Jun 10, 2008 at 16:01 UTC

    This is a terrific answer (++ to dragonchild below too). This embodies something I've been harping on lately -- why I really dislike XML::Simple and ended up with the decidedly not-simple XML::LibXML. The disguised/compromised complexity versus the consistent interface to the other layer (the DOM).

Re^2: API complexity measures
by zby (Vicar) on Jun 10, 2008 at 20:16 UTC
    OK - it might be hard to measure in the general situation - but sure there are cases where you can say that "this API is more complex than that one" in some objective way?

    Ad. consistency - this is another very interesting subject. How would you argument that one interface is more consistent than another one?

    My question is actually mostly about communication - what I want is to have a vocabulary and references to discuss those matters in some informed way. I understand that it might be very difficult - that is why I asked for references instead of expecting ready made answers.

      A trivial (but very important) example of consistency in an interface is to always pass the same parameters in the same order and, as far as possible, match the order to any relevant prior art.

      For example: if your API provides a number of move and copy related elements, you might ensure that they are all (target, source, length).

      To the extent that an API is consistent in the way it manages parameters, conceptual units, data structures and so on the API is consistent. 'Orthogonal' is often used and is a related concept.


      Perl is environmentally friendly - it saves trees
Re^2: API complexity measures
by zby (Vicar) on Jun 12, 2008 at 07:00 UTC
    This "simple API over a complex problem domain" sounds like "leaky abstractions" - is that what you have in mind? By the way this article describes a similar sentiment I think: Complexity of APIs.

    But I don't agree that measuring API complexity is hard - what is hard is judging if the complexity can be reduced without introducing "leaky abstractions", but you can have quite simple measures. By splitting the problem into two - first analysing the functionality and how much of it can be abstracted away - and then measuring the complexity of the API we can make the evaluation of an API more manageable.