views:

230

answers:

13

Can a program be written in more than one programming language? The stuff I read on The Daily WTF seems to imply that big companies/organizations employ several different languages when building a large application. How does that work? I know from working with Django that dynamic web pages are often put together with a bunch of different languages (Python for the controllers, HTML + Django's templating language for the view, and SQL for the models), but what about programs, ie stuff that would turn into an .exe when compiled?

+3  A: 

If the compilers for the different languages can produce the same format of object files, the linker doesn't care what language they were compiled from.

Alternatively, you can compile a .dll from any language and it works the same.

Anon.
+2  A: 

It is possible, although not very common. All languages are eventually compiled to assembly, so as long as each language uses the same ABI (calling conventions, etc.), modules compiled in different languages can be linked together. It's not common, though.

In addition, many programs use an extension language. For example, much of the user interface in World of Warcraft is written in the Lua extension language, even though the core WoW program is probably C++.

Rudedog
Languages inter-operating is actually *extremely* common.
Randolpho
I would agree its very common. Most programs are developed in the beginning with 1 core language. However, over time, as the program evolves, more languages are introduced.
Andrew Keith
Not all languages are compiled to assembly. Many are still interpreted. They're interpreted by assembly code, and they _could_ be compiled to assembly, but they're still interpreted.
Chris Lutz
ABI, or is that A*P*I?
Moshe
ABI - http://en.wikipedia.org/wiki/Application_binary_interface
Rudedog
+1  A: 

The short answer is Yes, the long answer is:

Yes, by doing one or more of the following:

  1. Building libraries and linking them together at compile time.
  2. Building dynamic libraries and linking to them at run time so you would have an exe and some dlls.
  3. In the case of frameworks like .net it doesn't really matter the language as long as it's supported by the framework, since it will either compile in the same type of code or the framework will know how to run it.
+3  A: 

Yes , you can certainly write programs in more than 1 language. What you need to do is modularize the program. For example write modules as DLL's. You can use different languages for each DLL if you want to as long as the interface between the DLL's is common.

I work on a program which has been in development for over 8 years. The program was developed in C++ years ago. Today, its .NET. The modularization is performed by building COM objects. This allows us to use a variety of languages and technologies for the same application. The oldest code I have is basic vanilla C and the newest is C# 3.5.

Andrew Keith
Indeed. My company's main product uses PowerBuilder, C, C# and VBA. We use ODBC, COM and OLE for various bits of inter-process communication. It's hard to do anything truly useful in one language any more.
DaveE
A: 

Yes, certainly. Trivially in Windows with .NET you could have C#, VB, and C++ in the same resulting assembly/DLL as these all generate IL object code.

When compiling to native on Windows or other platforms (Unix, Linux) many compilers generated object files in a standard/shared format. In that case, the linker can easily combine them into a shared library, static library, or final runtime (a.out or ELF binary in Unix terms).

This is often done as different programmers have different preferences and also since some language constructs lend themselves to better describe a specific kind of solution.

Kevin Brock
A: 

Most programming languages have a means for interfacing with C. When an application is put together from multiple different languages, it may be done by creating C interfaces for each of the different components and connecting the C interfaces, or the different components may actually be compiled into separate applications that communicate with each other using sockets or other forms of interprocess communication.

Michael Aaron Safyan
A: 

Yes, see http://en.wikipedia.org/wiki/Polyglot_(computing).

Adam Goode
A: 

Near the stone age in programming, when everything was written in assembly language, compiled languages came along. After some pain, grief, and years, it was hesitatingly acknowledged that writing at least some portion of an application in a "high level language" such as FORTRAN was a good thing. But many modules remained in assembly which contained things FORTRAN didn't do well, such as CPU trickery, tiny code space requirements, etc.

In an single application I worked on in the 1980s, we developed in FORTRAN, PL/M, 8086 assembly, and C. The language choices were driven by historical momentum plus ever improving compilers and build tools.

wallyk
A: 

Today it is very unlikely that you can get away with only one language.

Look at Adobe. All popular Adobe products are now containing more and more Lua scripting. They started with Lightroom and now there technical business strategy is to write the basic routines in C/C++/Assember (you need this for fast SSE graphics) and all the GUI is glued together with Lua.

Lothar
+1  A: 

The above answers (that I've seen so far) are all correct. Something else that isn't mentioned though is that companies/organisations define "large application" rather differently than programmers sometimes do.

To the health service, a hospital medical information system is a "large application" even if it actually involves, say, a bunch of different web servers, databases, various custom scripts for integrating various third party products, specially written client programs for radiology diagnostics, different web interfaces for doctors and nurses, and SMS system for paging doctors when results have been uploaded, etc.

In other words, where you might think "large application = 1 big binary", an organisation might think "large application = 1 noun for a bunch of big IT contracts, regardless of how many binaries are involved".

William Billingsley
A: 

Yes, it can be done. More often that not it is done because the target language doesn't have a certain feature or the said feature is easier to carry out in another language.

Michael Kelley Jr.
A: 

Performance is another reason to mix languages in a single application. In interpreted languages speed can be orders of magnitude slower than C/C++. Applications can have CPU-intensive portions written in C/C++ while leaving much of the program logic in the higher-level language to get the best of both performance and programming ease.

Kyle Lutz
A: 

It's quite common to build large applications using different langauges and technologies. Mixing languages comes in different ways.

First, compilers from different languages can produce compatible output that can be linked together. That can be .obj files from C, C++, Pascal and other languages compiling to native code. Or that can be .NET assemblies - you can effortlessly use an assembly written in any .NET family language from any other .NET family language assembly.

Then, there're various interoperability technologies. You could have some code wrapped as a COM object and consumed from an application in a different language. Or you could put code in different langauges into different programs and make them communicate via some interprocess communication technology like RPC. In the latter case they will not care at all how the other process works - they only send and receive messages - much like you don't care that your browser and the web server you read pages from are most likely written in different languages.

sharptooth