Geo
Geo

Reputation: 96997

What methods can we use to interoperate programming languages?

What can we do to integrate code written in a language with code written in any other language? Which techniques are more/less known? I know that some/most languages can be compiled to Java bytecode, but what do we do about the rest ?

Upvotes: 0

Views: 388

Answers (8)

T.E.D.
T.E.D.

Reputation: 44824

Almost every language that pretends some kind of system's development use is capable of linking against external routines with either a standard OS interface, or a C function interface. That is what I tend to use.

Upvotes: 1

Scott Vander Molen
Scott Vander Molen

Reputation: 6439

On the Web, cookies can be set to pass variables between ASP/PHP/JavaScript. On a previous project I worked on, we used this to create a PHP file for downloading PDFs without revealing their location on the file system from an ASP application.

Upvotes: 1

lothar
lothar

Reputation: 20267

Unfortunately your question is rather vague.

There are ways to use different languages in the same process usually by embedding a VM or an interpreter into the executable. If you need to communicate over process boundaries there again are several possibilities many of them have been already mentioned by other answers.

I would suggest you refine your question to get more helpful answers.

Upvotes: 1

cdonner
cdonner

Reputation: 37718

Direct invocations:

  • Direct calls (if the compilers understand each other's call stack)
  • Remote Procedure Call (early 90's)
  • CORBA (late 90's)
  • Remote Method Invocation (Java, with RMI stack/library in target environment)
  • .Net Remoting

Less tightly integrated:

  • Web services/SOAP
  • REST

Upvotes: 2

Brian
Brian

Reputation: 118935

I think there are a few possible relationships among programs in different langauges...

There's shares a runtime (e.g. C# and Visual Basic) and compiled into same application/process...

There's one invokes the other (e.g. perl script that invokes a C program)...

There's talks to each other via IPC on the box, or over the network (e.g. pipes and web services)...

Upvotes: 1

Walden Leverich
Walden Leverich

Reputation: 4556

You mention the "compile to Java" approach, and there's also the "use a .NET language" approach, so let's look at other cases. There are a number of ways you can interoperate, and it depends on what you're trying to accomplish, it's a case by case situation. Things that come to mind are

  • Web Services (SOAP or REST)
  • A text (or other) file in the file system
  • Use of a database to relay state or other data
  • A messaging environment like MSMQ or MQSeries
  • TCP sockets or UDP messages
  • Mailslots and named pipes

Upvotes: 5

Chris Bunch
Chris Bunch

Reputation: 89953

The two I see most often are SWIG and Thrift. The main difference is (IIRC) Thrift opens up a port and puts a server there to marshal the data between the different languages, whereas SWIG builds library interface files and uses those to call the specified methods.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1504182

It depends on the level of integration you want.

  • Do you need the code to share data? Use a platform-neutral data format, such as JSON, XML, Protocol Buffers, Thrift etc.
  • Do you need to be able to ask code written in one language to perform some task for code in the other? Use a web service or similar inter-process communication layer.
  • Do you need to be able to call the code within a single process? The answer at that point will entirely depend on which languages you're talking about.

Upvotes: 3

Related Questions