Lesson 6: Compiled vs. Interpreted
In our last lesson we discussed low-level languages (binary and assembly) as well as high-level languages. We mentioned that low-level languages are, at best, one program to a few devices and that high-level languages are almost always one program to many devices.
We also mentioned that high-level languages does this by being compiled or intrepreted. In this lesson, we’ll talk about what both of these terms means, and compare a few key aspects of the two.
Compiled
The term compiled has a meaning outside of the computer world, as I’m sure you know. A book can be compiled from multiple sources where the information is broken down, the pieces are put together in the appropriate order, and then it is bound into an easy to use book. Compiling a computer program is very similar.
When we compile a computer program, we take all of the code (which may be in different files), put the code together in the appropriate order, and then we bind it into a some single file (usually) which the computer can read. When I say “we”, I don’t actually mean the programmer. A program called a “compiler” (creative, eh?) is used to compile this code into a program.
The perks of compiling is that it is usually compiled into a file which the machine (or operating system) can read and run directly. Essentially, it is turned into a binary file, that is, a file written in the language of the computer.
One of the major perks of compiled languages is that they can run very quickly because the translating doesn’t have to be done at run-time (when the program is actually running) and is run in the computers native language, so it can run faster (as we discussed in our last lesson).
C++ and Visual Basic are two common compiled languages.
Interpreted
Interpreted languages, sometimes called “scripting” languages are languages which are never compiled and simply “interpreted” line by line as the program runs. A program called an “interpreter” is used to interpret this code and convert it to a binary version that computer can understand.
A nice thing about interpreted languages is that it doesn’t require compiling, which can sometimes require a lengthy amount of time for large programs, so we can quickly make changes.
Of course, a downside to interpreted languages is since we have to interpret the program as we run it, the speed and performance of the program takes a bit of a hit.
Javascript and PHP are both intrepreted languages.
Translated
You may occassionally come across the term of a “translated language”. This simply means converting a high-level language to low-level assembly language directly, so the programmer can use it as a low-level language. Languages like C are commonly translated and then the resulting assembly code is used on various devices.
If you see this term, just keep in mind that the language itself isn’t a “translated language”, it is simply a high-level language (either compiled or interpreted) that is translated into low-level assembly language (in a format the programmer can usually still modify).
Devices like digital microwaves may be programmed with a technique similar to this.
Take not that I may mention “translating”, but I won’t be referring to this. If I mention it in future lessons, it is simply referring to the traditional definition.
Not Quite Machine
Very rarely nowadays is it the case that the binary code generated by compilers and interpreters runs at the machine level. Usually when you compile, it is compiled into a manner that the operating system (Windows, Mac, etc.) can understand. These operating systems then have a layer on them which converts their special languages to the specific machine code for your specific hardware.
This extra layer is how high-level languages are able to achieve the one program to many devices, because they get a little assistance. A compiler or interpreter can be made to generate machine code, but the compiler or interpreter would have to basically embed this layer into the program itself.
Also, because each operating system’s unique “language” is different, you usually have to compile a program specifically for a specific operating system. However, you can still do one program to many operating systems, by simply compiling different versions of the same code. This is not unlike translating a book into English, French, Japanese, German, and so forth. The information is the same, it’s just said a bit differently.
Compiled and Interpreted
Some languages can be both compiled and interpreted. In fact, in theory, any language can be both compiled and interpreted. It really just comes down to what is most used and what programs are available for the language. Since both compiling and interpreting requires a program, it just depends what programs are available (or, if you are writing your own language, what programs you want to create).
Another consideration is how you want to use the information. For example, javascript works best as interpreted because it works on multiple operating systems. Each Internet browser which can use Javascript has it’s own Javascript interpreter embedded. Each of these programs translates the same code into a method that the current environment can understand.
If you were to compile Javascript, you would have to compile a different version for each environment. Then you would also have to figure out how to send the appropriate environment the appropriate version. This becomes a daunting task and quite impractical.
Since PHP is run at the server-level it is actually feasible to use compiled PHP, and there are a few compilers available. However, PHP is most commonly used as an interpreted language for ease of use, and because many compilers are commercial (paid) software.
There are even a few that are both at the same time. Java (not directly related to Javascript) is actually compiled. They are then run by a “virtual machine” found on the client system which runs the program. These virtual machines essentially act as interpreters by reading a compiled program (written in the virtual machines special language) and then converting it into the code that the machine (or operating system) can understand. The operating systems themselves can also be considered virtual machines in this sense.
So, compiled code is usually faster and more efficient, but it does have some drawbacks because you often need to maintain multiple copies of the same code. Interpreted code is usually a bit slower and less powerful, but is highly flexible.
Also, while I say one is faster and one is slower, we aren’t talking a race between the tortoise and the hare. The speed differences varies greatly from language to language, and with continual improvements in both interpreters and compilers, as well as the underlying hardware, the gap is constantly growing smaller.
In this lesson we learned all about compiled and interpreted high-level programming languages. In our next lesson we’ll finally move out of the background information and start looking at some more practical things, starting with variables.





September 21st, 2009 at 5:11 pm
I have just stared studing the theory of programing, however i was very confused about the difference of compiled vs interpreted until i came accross your page. this has helped alot thank you!