Search code examples
interopmultiple-languageslanguage-interoperability

How do multiple languages interact in one project?


I heard some people program in multiple languages in one project. I can't imagine how the languages interact with each other.

I mean there is no Java method like

myProgram.callCfunction(parameters);

never happens or am I wrong?


Solution

  • Having multiple languages in one project is actually quite common, however the principles behind are not always simple.

    In the simple case, different languages are compiled to the same code. For example, C and C++ code typically is compiled into machine assembler or C# and VB.Net is compiled into IL (the language understood by the .NET runtime).

    It gets more difficult if the languages/compilers use a differnt type system. There can be many different ways, basic data types such as integer, float and doubles are represented internally, and there is even more ways to represent strings. When passing types around between the different languages it must be sure that both sides interpret the type the same or - if not - the types are correctly mapped. This sort of type mapping is also known as marshalling.

    Classic examples of interoperability between different program languages are (mostly from the Windows world):

    • The various languages available for the .NET platfrom. This includes C#, VB.Net, J#, IronRuby, F#, XSLT and many other less popular languages.
    • Native COM components written in C++ or VB can be used with a huge variety of languages: VBScript, VB, all .NET languages, Java
    • Win32 api functions can be called from .NET or VB
    • IPC (inter process communication)
    • Corba, probably the most comprehensive (and most complex) approach
    • Web services and other service-oriented architectures, probably the most modern approach