Designing a cross-platform API

I am developing some "packages" of code (as we call them at my company) that provide fairly general functionality, and I would like to find a way to standardize the API across all the languages ​​we work with.

I am thinking about making the classes and test cases the same for every language, but with the implementation being language specific. This would mean that if we find a bug in one of the language implementations, we will need to check that it does not exist in others. My current philosophy is that as long as the class design and test cases are synchronized across languages, then this is an acceptable tradeoff in order to have some degree of "knowledge sharing".

So, I think the best thing in this case would be to simply check for class and method names, just to make sure that the calling convention is the same for every language, and that we are testing the same types of things, every single one too. Are there any tools out there for this, or am I better off just writing a few script to do the name validation?

And besides, am I considering this problem completely wrong? I'd really like to make our respective algorithms available for every language we need them in, but sharing or integrating code directly here is not an option (as an example, the two main languages ​​I need to support now are AS3 and C ++, so a shared library is out of the question). However, I feel like making it all generic and modular might come back to bite my ass later.

Any advice would be greatly appreciated.

0


source to share


1 answer


Different languages ​​have different conventions. If you're trying to build libraries that fit into the ecosystem around them, you may not need identical APIs.

Consider an object with a readable property:

// Java
Object propertyValue = myObject.getPropertyValue();

// C#
Object propertyValue = myObject.PropertyValue;

// Ruby
property_value = my_object.property_value

      



Even checking for something as simple as a property reader's name becomes heavily language-related. When this expands to more complex ideas, even the semantics of the implementations change. Let's look at event handlers in Java (listener objects) versus a callback based language (I'm using Matlab M right now). The same API will look at home in one environment and another in another.

Testing for identical behavior is easier and more expedient. One mechanism for doing this is to create a large amount of test data that implements your behavior, and then feeds exactly the same test data into unit tests in each language. Since the behavior should change, all you do is change the test data, view errors, and fix it.

+2


source







All Articles