Best practice for projects in multiple programming languages

Does anyone have any experience with this? I'm working on a Java decompiler right now in C ++, but would like a higher level language to do the actual transformations of internal trees. I'm curious if the overhead of marshaling data between languages โ€‹โ€‹justifies a more expressive and more expressive language to better articulate what I'm trying to accomplish (like Haskell). Is this really done in the "real world", or does he usually pick a language at the start of the project and stick to it? Any hints from those who tried it?

0


source to share


3 answers


I am a big believer in choosing the right programming language for every task. If there is another language that easily copes with some other difficult task, I would say it is necessary for this.

Is this happening in the real world? Yes. I am currently working on a project that consists of PHP and objective-c code.



The trick is, as you pointed out, the relationship between the two languages. If at all possible, let each language stick to its own domain and the two sections communicate in the simplest way possible. In my case, these were XML documents sent over http. In your case, some formatted text file might be the answer.

+2


source


Marshalling costs depend on the languages โ€‹โ€‹and architecture you work with. For example, if you are working in the CLR or JVM, there are inexpensive interoperability solutions, although I know you are working with possibly unmanaged C ++.



Another way is the built-in domain specific language. Tree transformations are often expressed through pattern matching and relatively few functions. You might consider writing a simple template tree template - eg. something similar to Lisp s-exprs, but uses placeholders to capture variables - with bound actions, which are functions that transform the matched subtree.

+1


source


John Ousterhout , the inventor of Tcl / Tk was a strong proponent of multilingual programming and wrote about it at some length. To do this, you need a clean interface between the languages โ€‹โ€‹you use for it. There are many mechanisms for this. Examples of different mechanisms for this are:

  • SWIG (Lightweight Packaging and Interface Generator can accept a c or C ++ (or several other languages) header file and an interface for a high level language such as perl or python, allowing you to access the API. There are other systems that take this approach ...

  • Java supports JNI and various other systems such as Python's ctypes , VisualWorks DLL / C connect are native mechanisms that allow you to explicitly build a call to a lower level subsystem.

  • Tcl / Tk was designed explicitly inline and has its own API for the C library to add hooks to the language. The constructs for this resemble the argv [] structures in C, and were designed to make it relatively easy to interact with a C Tcl command line program. This is similar to the example above, but coming from the opposite direction. Many scripting languages โ€‹โ€‹such as Python, Lua and Tcl support this type of mechanism.

  • Explicit glue mechanisms like Pyrex , which are similar to a shell generator, but have their own language to define the interface. Pyrex is actually a complete programming language. Middleware such as COM or CORBA allow a generic interface definition from the outside to a declaration in the interface definition language and language bindings for languages โ€‹โ€‹associated with the use of a common interface mechanism.

+1


source







All Articles