tags:

views:

102

answers:

1

I'm in the process of designing some code "packages" (as we call them at my company) which provide fairly generic functionality, and I would like to find a way to standardize the API across all languages that we are working with.

I'm thinking about designing the classes and test cases to be the same for each language, but leaving the implementation be language-specific. This would mean that if we find a bug in one of the language implementations, we'd need to check to make sure it didn't also exist in the others. My current philosophy is that, as long as the class design and the test cases are synchronized across languages, then this is an acceptable tradeoff for having some degree of "knowledge sharing".

So what I think would work best in this case is a simple check against class and method names, just to make sure that the calling convention is the same for each language, and that we are testing for the same types of stuff with each one, too. Are there any such tools out there to do this, or am I better off just writing some script to do the name checking myself?

And moreover, am I looking at this problem in completely the wrong way? I really would like a way to make our respective algorithms available for each language that we need them in, but sharing or integrating the code directly isn't an option here (as an example, the two main languages which I need to support now are AS3 and C++, so a shared library is out of the question). However, I feel that making everything this generic and modular may come back to bite me in the ass later.

Any advice would be greatly appreciated.

+2  A: 

Different languages have different conventions. If you're trying to develop libraries that blend into the ecosystem around them, you may not want 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 something as simple as a property reader's name becomes highly language-coupled. When this extends into more complex ideas even the semantics of implementations change. Consider 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 foreign in another.

Checking for identical behaviour is easier and worthwhile. One mechanism for this is to create a large volume of test data that embodies your behaviour, and then feed exactly the same test data into the unit tests in each language. As behaviour needs to change, all you do is change the test data, see what fails, and fix it.

Dan Vinton
I agree that using the same API might not be desirable. Just think about how easy it is to use DOM in Java - NOT.
Ilja Preuß
Also agree about the testing of behavior, although I would use unit tests. Take a look at Fit/FitNesse, which allows you to provide test data in a implementation language neutral way and gives you a framework for very easily writing the glue code to the API under test.
Ilja Preuß