Chrome is written in C++, Assembly and Python. How were they able to write three different languages and come up with one product? What i…

Chrome is written in C++, Assembly and Python. How were they able to write three different language… by @wimtenbrink

Answer by Wim ten Brink:

I’ve done projects that used even more languages! I’ve been using Delphi with Assembly, C++, PHP and JavaScript once for an application that would connect to a PBX Phone System. It worked as follows:

The Delphi application was the main executable and Delphi allows the use of Inline Assembly. This means I can combine Pascal with Assembly in a single source file.

The C++ code was used for creating a Shared Library, or a DLL file on Windows. A shared library exposes one or more functions to the outside through an interface that you can call from another module, like the executable I wrote in Delphi.

And this application ran as a service and was listening to port 80 so it would work as a simple web server. To create the web pages, I used PHP as the source for these web pages and called the PHP interpreter from my Delphi code while passing data as input and receiving the output of the PHP interpreter and collecting it as a string value. This string value thus became the response for each web request.

Basically, there are various techniques to combine multiple languages. The simplest method is when your compiler can actually handle two different languages. This is rare but some compilers will allow Assembly next to Pascal or C/C++.

A second technique is by linking the object files from one compiler with the object files of another compiler. This way, you could e.g. combine C++ and Pascal in a single executable, but both languages will cause conflicts in their runtime engines with one another if they are merged in this way due to memory management issues.

The third technique is by using Shared Objects. In these situations, each compiler generates a separate module that has it’s own runtime and will manage memory within it’s own context. There are some minor problems when you want to share memory between application and library because the allocated memory needs to be released again by the same language that allocated it!

And then you can just call a scripting engine for any scripted language. Most of those scripting engines are basically console applications with an input and output stream (and an error stream) which you can redirect within your code. Thus you would call the scripting engine to execute some script, send data over the input stream and read the output stream for the response. (And the error stream for possible errors.) This way, data goes back & forth between compiled code and scripting language.

There are even more inter-process communication solutions, though. I can start explaining them all but that would be way too much typing! Just check the Wikipedia page I just mentioned…

Chrome is written in C++, Assembly and Python. How were they able to write three different languages and come up with one product? What i…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s