Language interoperability


Language interoperability is the capability of two different programming languages to natively interact as part of the same system. Interoperability is advantageous because programming languages are optimized for specific tasks, and allowing them to communicate can create better systems.
There are many ways programming languages are interoperable with one another. HTML, CSS, and JavaScript are a form of language interoperability as they work together to render webpages. Some object oriented languages can do this thanks to the hosting virtual machine. High-level programming languages are usually interoperable with some lower level languages, an example of which is Apple's Swift and Objective-C.

Methods for interoperability

Object models

To facilitate interoperability between languages, one method is to use object models. CORBA and COM are the most popular object models. These standards provide a base set of rules for how object oriented languages would implement their data models to allow for a language-neutral way of implementing objects that can be used in environments different from the one in which they were created.

Virtual machines (VMs)

is software that emulates operating systems, and acts a buffer between the language and the hardware. This allows a program to run on any hardware or OS. An advantage to VMs can use these type systems to ensure the correctness of participating languages and gives languages a common ground for their type information. Another advantage is that languages designed for VMs compile into a low level intermediate language. The intermediate language then goes through its own compiler or interpreter which can do more types of optimization.

Challenges

Object model differences

With object oriented languages attempt to pair containers of data with code, but how each language chooses how to do that may be slightly different. Those design decision do not always map to another language easily. An example of this would be how different languages handle inheritance. A single class may have zero, one, or many superclasses. A common approach to this issue is defining a subset of a language that maps directly to the other, but can also fully understand the other language. This approach does mean in order for the superset to communicate down it will need to wrap some of its interfaces into classes that can be understood by the subset.

Memory models

Differences in how programming languages handle deallocation of memory is another issue when trying create interoperability. Manual and automatic deallocation is not the only issue but if it has deterministic and nondeterministic destruction. Based on the constraints of the language there are many different strategies for bridging the different behaviors. C++ which uses manual deallocation could use a Java styled garbage collector by changing deallocation behavior to delete the object, but not reclaim the memory. This requires that each object will have to manually be deallocated, in order for the garbage collector to release the memory safely.

Mutability

Mutability becomes an issue when trying to create interoperability between functional and object oriented languages. Languages like Haskell have no mutable types, where in C++ there are some constructs to flag classes as immutable but lack support of determining if something is mutable or not. Many functional types when bridged to object oriented languages can not guarantee that the underlying objects won't be modified.