Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using different languages in one project

I recently heard about the use of several different languages in a (big) project, I also read about famous services such as Twitter using Rails as frontend, mixed with some other languages, and Scala I think it was as backend.

  • Is this common practice? Who does that?

  • I'm sure there are disadvantages to this. I think that you will have problems with the different interpreters/compilers and seamlessly connecting the different languages. Is this true?

  • Why is this actually done? For performance?

like image 845
Tarbal Avatar asked May 17 '10 15:05

Tarbal


People also ask

Can a program have multiple languages?

Non-trivial software systems are not written in just one programming language. Instead, multiple languages are used; among these are the usual general-purpose programming languages (GPLs) like Java, C#, or Ruby, but also domain-specific languages (DSLs) such as SQL, HTML, or configurable languages such as XML.

Can you combine languages?

A mixed language is a language that arises among a bilingual group combining aspects of two or more languages but not clearly deriving primarily from any single language.


1 Answers

The question essentially comes down to Domain Specific Languages (DSLs). Sometimes one language is better suited for one part of the program, and another language for another program. The benefits (execution speed, or ease of development) often outweigh the drawbacks of mixing multiple languages.

  • Is this common practice? Who does that?

Very common; I'd say nearly every large application is written in more than one language.

Consider the example of a game. The core engine is usually written in C or C++ for speed and low-level hardware access, but behaviour of objects and characters are scripted in a higher-level language like Lua.

  • I'm sure there are disadvantages to this. I think that you will have problems with the different interpreters/compilers and seamlessly connecting the different languages. Is this true?

Yes, there is a certain amount of overhead to enable scripts to access the game objects and such.

  • Why is this actually done? For performance?

Yes and no. If performance were not an issue, the entire game could be written in a scripting language. Some other reasons are:

  • Speed of development; imagine the overhead if all the little objects and characters in a game like World of Warcraft were written in C++. The program would have to be compiled and restarted for every little change.

  • Modularity; new objects can easily be downloaded and added/removed at runtime, and savvy users can even mod them.

  • Portability; the same scripts will run unmodified on different platforms.

like image 169
Thomas Avatar answered Sep 19 '22 20:09

Thomas