Writing a program in two languages?

Can a program be written in more than one programming language? The material I read at The Daily WTF seems to imply that large companies / organizations use several different languages ​​to create a large application. How it works? I know from working with Django that dynamic web pages are often combined with a bunch of different languages ​​(Python for controllers, HTML + Django for presentation and SQL for models), but what about programs, i.e. will turn into .exe at compilation?

+4
source share
12 answers

It is quite common to create large applications using different languages ​​and technologies. Mixing languages ​​happens in different ways.

Firstly, compilers from different languages ​​can create compatible output that can be linked together. These can be .obj files from C, C ++, Pascal and other languages ​​compiled for native code. Or it can be .NET assemblies - you can use the assembly written in any native .NET language from any other assembly of the .NET family language with little effort.

Then there are various interaction technologies. You may have some code wrapped as a COM object and consumed from an application in another language. Or you could put the code in different langauges in different programs and make them exchange data using some interprocess processing technologies such as RPC. In the latter case, they don’t care how the other process works — they only send and receive messages — just as it doesn’t matter to you that your browser and the web server on which you read the pages are most likely written in different languages.

+3
source

If compilers for different languages ​​can create the same object file format, the linker does not care what language they were compiled in.

In addition, you can compile a DLL from any language, and it works the same.

+3
source

Yes, you can write programs in more than one language. What you need to do is modulate the program. For example, write modules as DLLs. You can use different languages ​​for each DLL if you want as long as there is a common interface between the DLLs.

I have been working on a program that has been under development for more than 8 years. The program was developed in C ++ several years ago. Today its .NET. Modulation is done by creating COM objects. This allows you to use different languages ​​and technologies for the same application. The oldest code I have is base vanilla C, and the newest is C # 3.5.

+3
source

Perhaps, although not very common. All languages ​​are ultimately assembled for assembly, therefore, if each language uses the same ABI (calling conventions, etc.), modules compiled in different languages ​​can be linked together. However, this is not common.

In addition, many programs use an extension language. For example, most of the user interface in World of Warcraft is written in the Lua extension language, although the main WoW program is probably C ++.

+2
source

Short answer: Yes, long answer:

Yes, by doing one or more of the following:

  • Building libraries and combining them at compile time.
  • Building dynamic libraries and linking to them at runtime so you have exe and some dlls.
  • In the case of frameworks such as .net, this does not matter much for the language if it is supported by the framework, because it will either be compiled in one type of code, or it will be known within the framework how to run it.
+1
source

The above answers (which I have seen so far) are correct. Something else that is not mentioned is that companies / organizations define a "large application" differently than programmers sometimes do.

In medical care, a hospital medical information system is a "great application", even if it includes, say, many different web servers, databases, various user scripts for integrating various third-party products, specially written client programs for radiological diagnostics, various web -interfaces for doctors and nurses, as well as SMS systems for paging doctors, when the results were downloaded, etc.

In other words, if you think “large application = 1 large binary”, an organization might think of “large application = 1 noun for many large IT contracts, regardless of how many binary files are involved.”

+1
source

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

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

This is often done because different programmers have different preferences, and also because some language constructs make it possible to better describe a particular type of solution.

0
source

Most programming languages ​​have tools for interacting with C. When an application integrates with several different languages, this can be done by creating C-interfaces for each of the different components and connecting C interfaces, or different components can actually be compiled into separate applications that exchange data with each other using sockets or other forms of interprocess communication.

0
source

Around the Stone Age in programming, when everything was written in assembly language, compiled languages ​​appeared. After some pain, sadness and years, he anxiously admitted that writing at least part of the application in a “high-level language”, such as FORTRAN, was a good thing. But many modules remained in the assembly, which contained things that FORTRAN did not succeed, such as processor tricks, tiny code space requirements, etc.

In one application that I worked in the 1980s, we developed FORTRAN, PL / M, 8086, and C in the assembly. The choice of language was determined by historical momentum, and also improved compilers and assembly tools.

0
source

Today it is very unlikely that you can leave with one language.

Take a look at Adobe. All of the popular Adobe products now contain more and more Lua scripts. They started with Lightroom, and now the technical business strategy is to write basic procedures in C / C ++ / Assember (you need this for fast SSE graphics), and the whole GUI is glued together with Lua.

0
source

Yes, it can be done. Most often this is not so, because the target language does not have a specific function, or this function is easier to perform in another language.

0
source

Performance is another reason for mixing languages ​​in one application. In interpreted languages, the speed can be several orders of magnitude slower than C / C ++. Applications can have processor intensive parts written in C / C ++, leaving most of the program logic in a higher level language to ensure maximum performance and ease of programming.

0
source

All Articles