A Guide to Compiled vs. Interpreted Programming Languages

Whether you’re looking to upgrade your computer science skills or dive into a new programming language, there is one question you’ll probably come across: compiled vs. interpreted languages. While these terms are thrown around a lot, the difference between the two is not always conveyed – nor why this matters when you start getting into programming.

In this article, we’re going to demystify compiled vs. interpreted languages and help you understand these important technical concepts from the ground up in the hopes these ideas better help you choose the right programming path for you.

How Computers Work

The first step to understanding the difference in compiled vs. interpreted programming languages is to gain a base understanding of how computers work.

Computer from the 1970s

Machine Code & Binary Code

Essentially, computers are just a bunch of electric signals. Sometimes we turn those signals off, and sometimes we turn them on. In a way, you can think of it as a more rudimentary version of morse code. And, like morse code, we can give these electrical signals values.

At the inception of this concept, we decided to assign simple values of 0’s and 1’s to indicate whether a signal was set to off or on. Then, we combined these 0’s and 1’s into sequences and gave each of those sequences meaning. For most people, you know this solution as binary, and binary code is the primary driving force behind machine code that makes computers actually work at the most basic levels.

At this point, though, you may ask why design computers like this? Well, in essence, in order for computers to work as fast as they do, we needed the simplest numerical values as possible to feed to the CPU. Without this, computers would probably eternally run as slow as dial-up internet that you were trying to access from a remote island. Thus, this clean solution gave us the speed we needed to do all the things we do on computers.

Hands on a keyboard coding

What is a Programming Language?

All the above being said, you might be aware that we do not generally code in binary. Of course, you can definitely code in binary (or hex-numbers which are easily translated to binary) if that is your heart’s desire. However, do know it will be a big challenge!

Instead, people found an easier way to get around this: programming languages.

Programming languages are quite similar to foreign languages. They provide us a structured way with vocabulary and “grammar” (i.e. syntax) to communicate something – in this case, instructions for how to perform a certain task. Instead of 0’s and 1’s, programming languages were made with humans in mind so we could easily read and write with them in order to achieve the functionality we desire. Now, there are some nuances required here, as we still need to communicate that functionality in a way that’ll be compatible with computers (i.e. machine instructions). But writing a loop is much easier than writing 10,000 characters of binary to achieve the same effect.

However, as you might have guessed, we can’t exactly feed this human-readable language to a computer that only really understands binary. So, we need some way to translate what a programming language says into a binary format that the computer can read. Perhaps if we had some way to compile this translation, or maybe even interpret it on the spot?

And thus, we come to the main topic of this article: compiled vs. interpreted languages.

Programming Languages to Machine Code

Briefly, let’s now outline what a compiled language is, and what an interpreted language is. Bear in mind when diving in, many languages can use both types of compilation methods (example: Python). However, in general, most languages have a pseudo default method, which is why it’s useful to divide languages into these categories. We’ll also be covering a third category here involved with translating code into machine language that is intertwined with the two main ones: just in time compilation.

What is a Compiled Language?

A compiled programming language is one that uses a compiler to translate a program into machine code before execution time. Once a program is done being coded, compiled languages go through what’s commonly called a “build” step. This build step basically instructs the compiler – which has instructions on how to translate a programming language – to do its translation work and create, essentially, a new file that is in binary. Then, when you execute the program, the computer goes straight to this binary file and executes the program according to those compiled instructions that are already prepared for the computer to understand.

Examples of Popular Compiled Languages: C++, C#, F#, Go, Kotlin, Python (can also be interpreted), Rust, Swift

What is an Interpreted Language?

An interpreted programming language is a language that uses an¬†interpreter to translate a program into machine code¬†at the time¬†of execution. Unlike compiled languages which take an extra “build” step to work, interpreters translate things more or less in real-time. As such, the minute you start executing your program, the interpreter goes to work translating things line-by-line right then and there without needing to create extra files to do so. Think of it as human interpreters during big speeches who listen and translate into sign language right then and there for users who are hard of hearing.

Examples of Popular Interpreted Languages: JavaScript, Lua, Perl, PHP, Python (can also be compiled), Ruby, PowerShell

What is a Just-In-Time Compiler?

While we haven’t mentioned it yet, there is one type of compilation that is highly related to both compiled & interpreted languages and worth talking about: just-in-time compilers. The idea behind just-in-time compilers is to capture the benefits of both compilers and interpreters (which we discuss more below). These sorts of compilers analyze the code during execution and take the most critical parts and pre-translate them into machine code. While execution is slowed during the analysis, which can happen often, the overall benefit allows you to bypass some of the issues of regularly interpreted languages – mostly the part where they’re slower in general.

Examples of Languages That Can use Just-In-Time Compilers: Java, C#, Scala, Visual Basic

Woman working at a laptop and drinking coffee

Compiled vs. Interpreted: Advantages and Disadvantages

So we understand what compiled vs. interpreted means at the most fundamental levels. However, why would one choose one type of language/compilation method over another. In this section, we’re going to outline the main advantages and disadvantages between compiled and interpreted languages.

Execution Speed

Most often when discussing compiled and interpreted languages, this may be the first point you come across. And it’s for good reason, as this is usually the primary deciding factor for many different developers.

As explained above, compiled languages have the code translated before execution, and interpreted languages do it at run-time. You can think of this as being the student who does their homework the night before class, vs. the student who does it while everyone is handing in their papers to the teacher.

Since the student who does it the night before is already prepared, the whole ordeal of turning the homework in is much faster – and the same can be said of a compiled language. The computer already has the machine code built, so it just needs to look at the right file to read. This makes running the program faster since there’s no extra legwork to do. This is also why many games, which need extra fast runtime, use compiled languages like C++ to get the job done.

Meanwhile, the student trying to finish their homework in class is going to slowly sneak to the back of the line and not turn their work in right away. Interpreted languages do the same. So, in essence, they do run slower and just don’t execute programs as quickly since they’re translating in real-time. Now, keep in mind, for small programs, we’re talking about a matter of milliseconds which doesn’t really matter to the average human. But, for bigger programs, especially those with sizeable databases, speed is integral for getting it done as quickly as possible.

Racing car from Unreal engine project

Compilation Steps

There is another “pseudo speed” difference in the compiled vs. interpreted discussion that goes beyond execution: compilation steps. By this, we mean how fast we can get from the raw code to whatever the computer needs to execute it as fast as possible.

In this regard, interpreted languages actually have the advantage. Since interpreted languages are translated at runtime, there are no actual extra steps for you as a developer to take to get from code to execution. Usually, all you need to do is trigger the execution, and boom, your code is running and executing on command.

As established earlier, though, compiled languages do need an extra “build” step in order to get from code to an executable application. How long this build step takes varies greatly from program to program and largely depends on complexity. For example, your simple “Hello World” script will probably take less than 1 second to compile. On the other hand, your open-world game with 100s of characters and scripts is probably going to take quite a few minutes at best.

You can think of both “speeds” as a pair of trade-offs. Compiled languages sacrifice compilation “speed” for faster execution, and interpreted languages sacrifice execution speed for faster compilation.

Modification Flexibility

For compiled and interpreted languages, this point is heavily tied to the last point regarding compilation. When we talk about modification flexibility, we’re talking about how easy it is for a programmer to edit their code and then re-run it. This is monumentally important to discuss, as you will be rewriting code a lot, no matter your skill level.

Similarly again to the above, interpreted languages win out the advantage here. Because the translation is taking place at runtime and there is no real compile time; you can edit your code at any point and immediately go back to execution. In fact, you can even edit the code while the program is running and not suffer any real ill effects! It is indeed that simple.

With compiled languages,¬†anytime¬†you change your code, even if it’s just to add a missing semicolon, you have to compile the program again. Since this compiling can take a bit, you can imagine that this quickly adds up and makes modification not the quickest or most flexible task all the time. As such, you do need to be a lot more mindful before you compile your programs again and can’t just edit on the fly.

Man working on a laptop on a surfboard in the ocean

Compilation Error Handling

Another one related to compilation a bit for compiled vs. interpreted languages is errors. In other words, what does your compilation method do when it hits compilation errors in the code? This one is more difficult to say who has an advantage or disadvantage, as this will depend on when you want to catch these errors.

Compiled languages flat out won’t let you compile things if there are coding errors that would affect compilation.¬† In general, most compilers just stop the translation process and notify you why the compilation process failed. On the one hand, this makes it so you aren’t executing programs that would have suffered critical errors anyway. So, this allows you to tackle problems before they become problems. However, this can make it harder to debug programs since you can’t test the execution without fixing certain errors – some errors which you may struggle to find without this execution.

Interpreted languages will allow you to run programs with errors, and simply log when those errors occur. As such, it has the advantage of letting you do all your debugging at runtime, and your program will continue to try and run as best it can in the circumstances. That being said, this also means you won’t know about these compilation errors until the program hits them. This might be fine for a small program, but if you have 1000s of lines and one function gets rarely called, you may never even see this error come up before the program is live.

So, all in all, this one depends on what you as a developer want!

Portability

The last major advantage/disadvantage to discuss for compiled and interpreted languages is about portability.¬† In this respect, we’re talking about how easy it is to use a program from device to device.

This is a section where compiled languages are at a bit more of a disadvantage. One thing we’ve neglected to mention in this post so far is that, when compiling things to machine code, the compiler does so while aiming at a specific target platform/CPU. As such, you can’t just take a file meant to run on a mobile phone, pop it into the computer, and have the computer execute that same compiled binary file with no issues. Each platform requires its own unique method of compilation to work. So, if you want your program to work on multiple machines, you have to compile a separate file for each target platform – which obviously takes time.

Interpreted languages do not have this drawback. Since things are translated at runtime, they’re very platform-independent and don’t really require any extra steps of compatibility. This is a large reason why languages like JavaScript are heavily used on the internet. As this is an interpreted language, it’s cross-platform compatible regardless of how you access the JavaScript program. Other interpreted languages have the same experience, so for the ultimate cross-platform abilities, this is a direction to consider.

Woman walking around looking at mobile phone

Why Compiled vs. Interpreted Matters

Before we end this post, we want to take a brief moment to discuss one last part in the compiled vs. interpreted space: why this matters.

Different Programs Require Different Execution Speeds

We touched on this above a bit, but this point is worth reiterating. No matter how you look at it, compiled languages execute faster, even if the compiling process takes longer. And, depending on what you’re trying to program, this can have some immense implications.

For example, notice the difference in games that are browser-only vs. a AAA game like Soulcalibur VI. Most browser-based games are made with JavaScript, an interpreted language, and therefore wind up smaller in scope. This is largely due to the sheer fact that interpreted languages somewhat limit how fast those games can run. So, to keep them lag-free, developers must make them smaller Рwhether graphically or programmatically.

However, with¬†Soulcalibur VI, there is a lot more room to do complicated graphics and mechanics. As this game was based on C++, a compiled language, the game is able to take advantage of the speed to provide a more comprehensive experience with intense 3D graphics – something you wouldn’t with a browser game.

All in all, though, what this means for you is that you need to pick a language that suits your project. If you want to build a huge open-world MMORPG with 3D graphics, you wouldn’t really want an interpreted language since you need speed. On the other hand, if you’re just making a simple quiz game and speed isn’t a factor, an interpreted language is fine, and in some situations may even be better. So, this distinction is very important for scoping your projects correctly.

Virtual pet game example made with JavaScript

Code Editing May Need to Be Faster or Easier

When you start diving into higher-level concepts like machine learning, the last thing you’re going to want to do as a developer is clog up the front-end with compiler time. Unfortunately, this is what compiled languages will do, even if it takes less than 1 second to compile your project. Sometimes, you really do need to be able to quickly test certain features, lines of code, or so forth in order to complete it. And sometimes you may need to do real-time tests to ensure certain data is being processed correctly.

If you feel you’re working on something that needs to be more easily edited on the fly, then interpreted languages are probably a better bet – and why knowing the difference is important. In so doing, you can pick a language you can execute at the drop of a hat and ensure whatever complicated program you’re trying to make actually works as intended.

Overall, though, you’ll want to understand the difference between the two compilation types so you can make a good choice for your project.

Cross-Platform Considerations

Another reason this difference matters comes with the portability factor which we’ve explained above. If you need something that can easily be accessed from other devices, then you may want to go with interpreted code. This way you don’t have to worry about certain compiler-related factors, and can focus on your project. This may especially be the case if you’re making something like a web app where you need to be sure phones and PCs can easily use it out of the box and you don’t bog your site down with multiple execution files.

Either way, at the end of the day, it’s much easier to make a cross-platform program work on multiple devices with an interpreted language than it is with a compiled language. That being said, most compiled languages can be easily made cross-platform as well, as programs like Unity and Unreal Engine (just for example) come with easy one-click solutions that let you build your projects without too much fuss. The only consideration really is it just takes more time as you have to make separate builds for each device.

Nevertheless, knowing the difference helps you make yet another informed decision for what language will best suit your project.

Example of a physics game made for mobile

Ending Words

Understanding the difference in compiled vs. interpreted languages can definitely be important. Not only can it influence which language you pick for your project in the first place, but how you work with the project in general with the actual programming part. Plus, knowing the difference gives you a huge advantage in the computer science space, as these key concepts will help you dive into other aspects about how computers work. That being said, remember both compiled and interpreted languages are just tools to help you get to a particular goal.

Before we end, we did want to provide you with a few more resources below to help you dive further into learning a programming language and picking one that works for you. Regardless of your choice, though, we hope you’re better equipped to program your dream projects!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.