9

In a system which requires use of multiple languages, what are the best practices to ensure a loosely-coupled architecture when code is calling another language's code?

APC
  • 137,061
  • 19
  • 153
  • 266
GurdeepS
  • 58,809
  • 95
  • 236
  • 371

3 Answers3

2

Write the API in C. Many modern languages can call or incorporate C code with little to no hassle. C++, Vala, Python, D, C#, Many Lisps, VB, and Java, just to name a few, allow the use of C code in shared libraries. In this manner, as long as you have a sane interface you can easily call your code from most any language. C is the lowest common denominator of modern computing.

Robert Mason
  • 3,649
  • 3
  • 28
  • 41
  • That is the same as using java byte code interoperability for JVM based languages. – Gabriel Ščerbák May 02 '10 at 10:19
  • perhaps you mean CIL. http://en.wikipedia.org/wiki/Common_Intermediate_Language – Sky Sanders May 02 '10 at 16:10
  • @SkySanders I know it's an older comment but no, OP is referring to literal native C code and the other commenter is referring to JVM bytecode which is specific to JVM languages (Java, Scala, Kotlin, Clojure, Groovy, etc.) where as CIL, implemented by .NET languages on the CLR (C#, F#, VB.NET, etc.) as well as some others. – Adam Jan 12 '21 at 12:55
1

Hmm, this is quite a hard question, the answer iMHO depends on the way the languages interact.You can use some sort of message passing interface, message queue or even some middleware, e.g. CORBA or even maybe web services. E.g. for JVM languages you can use the interoperability features provided by the virtual machine(scripting engine). Maybe if you give more details, we or someone else will get to some usable solution.

Gabriel Ščerbák
  • 16,864
  • 8
  • 33
  • 50
0

IMO, there is no way to answer this question before you can at least elaborate on the "system" mentioned in the question. Is the "system", for example, a mobile phone, a single machine, a virtual machine like JVM or CLR, a group of servers on a LAN or spanned across the internet? In different kinds of "systems", there are different optimal solutions, so could you elaborate a little more?

Zhang Yining
  • 186
  • 1
  • 3