What is the difference between compiled, interpreted, and JIT (Just in Time) languages?

Ronaldo B.July 27, 20225 min read

In this article

When we're learning programming, it's very common to hear the expressions “Compiled language” and “Interpreted language.” It's even common to witness some discussions about which of these options is better and more advantageous.

But perhaps we ask ourselves: “What is the difference between these structures after all?” In this article, we will explain this difference and also show the advantages of each one.

To start, we need to remember what our objective is when creating a program. Our goal is for the code we develop to be executed by the computer so we can see a result on the screen, no matter which programming language we have used.

In order for the program to be executed by the computer, it needs to be in a language that the CPU can understand. And we know that the computer does not understand programming languages. For instance, we cannot say that a computer can read PHP, JavaScript, Python, or C++. The computer understands machine language, based on the binary system (0 and 1). Thus, we need to transform our code into binary for it to be executed. To achieve this goal, we have different “strategies” or architectures. We can do this by 1) compiling our code or 2) interpreting it. We will talk about each of them now.

Compiled Code

The first option we have is to compile our code. The verb “to compile” can convey the idea of converting one object into another. Thus, we can say that the compilation process involves converting our code into machine language through a program called a compiler.

The verb “to compile” can also mean to condense a vast object into a final result. This helps us understand another process that the compiler performs. It converts all our code at once. In other words, it seemingly selects our entire code, converts it to binary, and stores the result in a single “package,” as if it were a “zipped file,” which is sent to our end client already ready to be executed. A summary of this process can be seen in the image below:

Summary of how compiled code works

The compilation process brings many advantages. Firstly, the end client does not have access to the source code of our project, as they only receive the binary code to be executed. Another advantage is performance. Since we compile the entire code, we do not need to repeat this process unnecessarily. Additionally, we will already have everything necessary for execution at hand, which greatly speeds up this process.

Some examples of programming languages that are compiled are C++ and Objective-C.

Interpreted Code

Another type of code we have is interpreted code. When we think of interpreting, we might imagine someone who works as an interpreter. This involves receiving information from a source language and transmitting it in a translated manner to a target language.

An interpreted language performs a similar process. It will be interpreted through a program called an interpreter, which will then convert our code to machine language. However, this process will occur gradually, as the interpreter will perform the conversion by analyzing line by line, rather than the entire program, unlike what happens with the compiler.

The image below provides a summary of the interpretation process:

Summary of how interpreted code works

We can see that the interpretation process will be slower, as it will be executed repeatedly, which decreases performance. We know that our end user will likely not notice this speed difference, as it occurs “behind the scenes.” However, we understand that this is a very important factor in any program.

Even with the performance disadvantage, interpreted languages have the advantage of being simpler to “debug.” Since interpretation occurs gradually, we can more easily visualize the errors that may appear, and if we find any issues, we can promptly resolve them. This is an advantage of interpreted code over compiled code, which is more difficult to debug since the entire code is executed at once.

Some examples of programming languages that are interpreted are PHP, JavaScript, and Python.

After this analysis, we can weigh the pros and cons of compiled and interpreted programs. However, there is still a third alternative that can merge both concepts and bring us many benefits.

JIT - The merging of both concepts

The next architecture we will analyze is JIT, which stands for “Just in Time.” Do not confuse this term with Toyota's production system, which popularized the term ?. Although it is a different term, this programming concept has a similar objective to what was implemented by the Japanese automaker. That objective is to optimize production.

When we talk about JIT in programming, we are referring to a technique that involves merging concepts of compiled and interpreted code. With JIT we continue to interpret codes. However, we will also compile them, but only the part of the code that we will use at the moment of execution. This represents a significant increase in performance. Since we will use the compilation process, which is already fast, and it will be executed in isolated parts of the code, only at the right time (“just in time”).

Thus, we have at our disposal “the best of both worlds.” We have the speed of compilation along with the simplicity of debugging our code.

Languages that implemented the JIT technique have noticed significant changes in the performance of their codes. Among these examples are JavaScript and PHP starting from version 8.

Conclusion

In this article, we learned the difference between compiled and interpreted languages. And we also learned about a technique that takes advantage of the best of each of these architectures, JIT. We hope that this explanation has helped us understand a little better the process necessary for a program to be executed. With these concepts in mind, we are also more prepared to decide which languages to use considering their architectures and the circumstances and requirements of each project we will work on.

Until the next article ?.

Keep learning with Hcode

Sign up for the course platform and follow the next blog guides.