Question

I have a strong interest in functional languages, because they have so many advantages, but I don't know if they are really used in practice and how well they can be integrated into a mainstream Java, C# or C++ environment. Could a programmer, who works in a team with other programmers that don't know any functional language, use it combined with other languages? It's a problem when others don't understand the code that one team member produced, but Java byte code that has been written in Scala, could be easily decompiled to pure Java.

I know that integration works pretty well between Java and Clojure and Java and Scala, but what about other languages like C++?

Was it helpful?

Solution

I have a strong interest in functional languages, because they have so many advantages, but I don't know if they are really used in practice

They definitely are, although not nearly as much as object-oriented or procedural languages.

how well they can be integrated into a mainstream Java, C# or C++ environment.

There are three different definitions of "integrated into another environment." I list them here in order of preferability. The first one is much more sane than the last one.

  1. A common thing to do is to use Java or C# on the front end, and then Erlang or Scala or something on the back end. This means that two different teams use two different languages and do completely different things. The integration is on the product level, and the two different parts communicate via a network protocol or something.

  2. A second kind of integration is about using e.g. a Java library in Scala, and that happens quite a lot, even with other languages. This requires the calling language to be able to call functions from the library language.

  3. There's also "integration" in the sense that the same team works on the same program in both C++ and Scala, which is both difficult and rare.

Could a programmer, who works in a team with other programmers that don't know any functional language, use it combined with other languages?

Could? Sure. Should? Definitely not. For teamwork to work the team must be in agreement about what languages they know. The team are the guys who are going to review, help document and bug fix the code, so they should be able to read it.

It's a problem when others don't understand the code that one team member produced, but Java byte code that has been written in Scala, could be easily decompiled to pure Java.

Not in a way that's remotely practical to read. Since Scala works so differently, its byte code looks really weird as well.

I know that integration works pretty well between Java and Clojure and Java and Scala, but what about other languages like C++?

Many languages provide an FFI (a foreign function interface) which is a way to call functions written in other languages from your language. Haskell has an FFI for C code, which means that you can use any C library with your Haskell code. This is language dependent and it's difficult to give any sort of general answer.

It is apparently possible to call C/C++ from Java, so it stands to reason that it should be possible from Scala or Clojure as well.

OTHER TIPS

Haskell has a pretty mature C foreign function interface. I've only ever used it to call down into C libraries, but the opposite is possible as well.

Could a programmer, who works in a team with other programmers that don't know any functional language, use it combined with other languages?

Yes. This is typically achieved via a "foreign function interface". Depending on your language implementation there will be more or less support for calling to or from your language, from other languages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top