views:

136

answers:

5

I'm working now on an API for developers feature of our product.

The first version was released and it has small number of users at the moment. Since I started to develop its second version, some parts were reworked, some parts were removed to make the API more elegant and clear.

But the 2nd version deployment can be a pain for old version users. Our marketing department is planning to enhance our API product a lot, add more features to it.

How should I build the system, so
1) we wouldn't be constrained to the "old version" to add new interesting features
2) current API users won't be dissatisfied because of the need to rework their systems in order to comply with the changed API

Or should the API products be tested in a sandbox for quite a long period of time before the public release, so there wouldn't be any significant modifications in the specification?

+5  A: 

When you have to make changes to the API which already has some users, probably the best route is to deprecate the old API calls and encourage use of the new calls.

Removing the capability of the old API calls would probably break the functionality of old code, so that is probably going to cause some developers using your "old" API to become somewhat dissatisfied.

If your language provides ways to indicate that certain functionality has been deprecated, it can serve as a indication for the users to stop using old API calls and transition to new calls instead. In Java, the @deprecated javadoc tag can provide notes in the documentation that a feature has been deprecated, or from Java 5 the @Deprecated annotation can be used to raise compile-time warnings on calls to deprecated APIs features.

Also, it would probably be a good idea to provide some tips and hints on migrating from the old API to the new API to encourage people to use the new way of interacting with the API. Having examples and sample code on what to do and what not to do, the users of the API would be able to write code according to the new, preferred way.

It's going to be difficult to change a public API, but with some care taken in the transition from the old to new, I believe that it the amount of pain inflicted on the users of the API can be mitigated to a certain extent.

Here's an article on How and When to Deprecate APIs from Sun, which might provide some more information on when it would be appropriate to deprecate parts of APIs.

Also, thank you to David Schmitt who added that the Obsolete attribute in .NET is similar to the @Deprecated annotation in Java. (Unfortunately the edit was overwritten by my edit, as we were both editing this answer at the same time.)

coobird
+2  A: 

It's a balance you will have to strike with your community:

  • Keep old functions for aeons and you'll end up with the Win32 API (30000 public functions)?

  • Rewrite the API all the time, and you can get something similar to .NET, where a new revision goes out every so often (1.0, 2.0, 3.0, 3.5...) and breaks existing programs or introduces new and improved ways of doing UIs etc.)

If the community is tolerant of change and open to experimenting, you will strive for a lean, current API and know that some breakage, aka bit rot, will result. If, on the other hand, the community has tons of legacy code and no resources or desire to bring it up to the latest version, you must keep backward compatibility or all of their stuff will simply not work on the new API.


Note to one of the other answers: deprecating APIs is an often-used way of indicating which functions are "on the way out", but as long as they work, many developers will use them even in the new code because those are the functions they are used to. There are very few enlightened developers that have both the awareness to actually heed "Deprecated" warnings and the time to search the code for other instances of the old API and update them.

MaxVT
+2  A: 

Microsoft is pretty famous for their insane backwards compatibility. One of the things they did was to keep all the old obsolete calls, and then add new ones that new programs could use to access the enhanced features that they could not work into the old API.

You did not specify which programming language you use, but both .NET and Java has a mechanism to mark certain API calls as obsolete. If backward compatibility is very important for you, you might want to take the same route.

tomjen
A: 

Backward compatibility should be the default. The only reason you should compromise this principle is when the API is somehow insecure which forces users to change to more secure methods.

jm04469
+1  A: 

Idealy applicitations written to your original API will continue to work with the new version.

One way to add new features while at the same time making sure that old applications continue to run is to have two versions of an API call.

For example, suppose you currently have a function Foo that takes 2 parameters (arguments) in the API but you decide the new version really should take 3 parameters. Keep Foo the way it is and add a new function Foo2 which takes 3 parameters.

That way users can continue to code against Foo for backward compatibility or use the new Foo2 function if they require the new features.

This technique has been commonly used bu Microsoft for the Windows APIs.

JonnyBoats