Interpreted vs. Compiled Languages: What’s the Difference?

Have you ever wondered what the difference between interpreted and compiled programming languages is? If so, read this article now to find out

If you want to get into programming, you’ve probably already heard about interpreted and compiled programming languages. But what actually are interpreted and compiled languages, and what is the difference between them?

In the following, I am going to explain it to you!

Introduction

Every computer program is nothing else than a set of written instructions stored in a file. However, it is impossible for us humans to write code that the computer can directly understand. Hence, we’ve got programming languages that make it easy for us to give instructions to a computer. Nevertheless, the computer still can’t understand this language and has to translate it into its own language first.

Whether a language is interpreted or compiled determines how or when the programming language is translated into binary code that the computer can understand.

Interpreted and Compiled languages - How it works

What is a compiled language?

Imagine you want to read a book. However, the book is written in a language you can’t understand.
One possible option for you to read the book would be to have it translated entirely before you read it.

The same principle can be applied to compiled programming languages, as they translate the programming language into machine code (binary code) entirely before the program actually gets executed.

Because compiled programs are already translated into machine code before the execution, they usually are faster than interpreted languages.

The program that does the translation is called a compiler. It usually compiles your code into a directly executable file
(e. g. a .exe file).

Some common examples of pure compiled programming languages are:
C++, C, Rust, and Go

What is an interpreted language?

To come back to our example from before:
Another way of being able to read a book that is not in your language is to have it translated line by line or page by page.

That is exactly what an interpreter does. It reads the code at runtime and translates it line by line into binary code.

In theory, you could even program a program while it’s already running (e. g. in a console window like you can do with Python).

Interpreted languages used to be significantly slower than compiled languages because they have to be translated at runtime. However, the difference isn’t that big anymore nowadays.

Also, interpreted languages need to be interpreted every time they get executed, whereas compiled languages only need to be compiled only once as long as the source code doesn’t change.

Some common examples of interpreted programming languages are:
Python, PHP, Ruby, and JavaScript

Conclusion

In conclusion, compiled languages get translated entirely before execution, whereas interpreted languages get translated into binary code line by line at runtime.
Additionally, you need to know that some mainly interpreted languages can also be compiled. (e. g. Python)

Advantages of compiled languages:
  • Faster than interpreted languages
  • Users don’t need to have a compiler/interpreted installed to run a program if it already has been compiled
  • Code only has to be compiled once
Advantages of interpreted languages:
  • The compilation is an extra step that manually has to be done before execution
  • Platform dependence of the compiled binary code
Disadvantages of compiled languages:
  • More flexible
  • Smaller program size
  • Code is platform-independent
Disadvantages of interpreted languages:
  • Slower than compiled languages
  • Users need to have an interpreter installed to run the code on their own computer

Thanks for reading!

Share this article

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *