When choosing a pro­gram­ming language, two things in par­tic­u­lar need to be taken into con­sid­er­a­tion: the language needs to provide all the necessary building blocks for the planned software project, and pro­gram­ming and im­ple­ment­ing the project should be as simple as possible. Being easy to read and having simple code are essential to ensuring the latter because these char­ac­ter­ist­ics make it easier to get started with and learn a pro­gram­ming language, as well as to use it on a daily basis.

In order for the in­struc­tions of a written program to then be un­der­stood by a computer or processor, the source code of modern pro­gram­ming languages must first be converted into a machine-readable form. This is done with either a compiler or an in­ter­pret­er depending on the pro­gram­ming language. What exactly do these two tools do? And how do they differ from one another?

What is an in­ter­pret­er?

An in­ter­pret­er is a computer program which processes the source code of a software project during its runtime (i.e. while it is running) and acts as an interface between the project and the processor. In­ter­pret­ers always handle code line by line so that the in­di­vidu­al in­struc­tions of each line are read, analysed and converted for the processor one after another. This also applies to recurring in­struc­tions which are executed each time they occur. In­ter­pret­ers use their own internal libraries to process software code: once a line of source code has been converted into the cor­res­pond­ing machine-readable in­struc­tions, it is sent directly to the processor.

The con­ver­sion process is not complete until all the code has been in­ter­preted. It will only stop early if an error has occurred during the pro­cessing. This makes debugging much easier since the line of code con­tain­ing the bug is im­me­di­ately iden­ti­fied when the error occurs.

Note

Some of the most popular pro­gram­ming languages which primarily rely on an in­ter­pret­er when con­vert­ing source code into machine code include BASIC, Perl, Python, Ruby and PHP. These are often referred to as “in­ter­preted languages”.

What is a compiler?

A compiler is a computer program which converts the source code of a software project in its entirety into machine code before it is run. Only then is the project run by the processor which means it has all the in­struc­tions available to it in machine code right from the start. The processor thus has all the necessary parts ready to run the given software, process input and generate output. In many cases, there is a crucial in­ter­me­di­ate step which takes place during the compiling process: before being converted into machine code, most compilers will often first convert it into an in­ter­me­di­ate code (i.e. “object code”) which is often com­pat­ible with various platforms and can also be used by an in­ter­pret­er.

When gen­er­at­ing the code, compilers determine the order in which in­struc­tions are sent to the processor. If the in­struc­tions are not dependent on one another, the processor can even execute the in­struc­tions sim­ul­tan­eously.

Note

Included among the pure compiled languages, you will find the in­flu­en­tial languages C, C++ and Pascal.

Compilers vs. in­ter­pret­ers: overview of the dif­fer­ences in a table

Both compilers and in­ter­pret­ers are used to convert written software code into a machine-readable ex­ecut­able format. Computer pro­cessors require this converted code in order to run programs in languages such as C, C++, PHP, Python and Ruby which makes these two tools essential for using desktop computers, laptops and smart­phones. The brief de­scrip­tions given above have already shown that there are important dif­fer­ences between compilers and in­ter­pret­ers which must be taken into con­sid­er­a­tion, par­tic­u­larly when choosing the right pro­gram­ming language for new software. The following table sum­mar­ises the most important points when comparing compilers and in­ter­pret­ers:

  In­ter­pret­er Compiler
When is the source code is converted? when the software is running before the software is run
Con­ver­sion procedure line by line always the full code
Code error no­ti­fic­a­tion after each line collected after it is fully compiled
Con­ver­sion speed high low
Con­ver­sion ef­fi­ciency low high
Amount of de­vel­op­ment work low high
Common languages PHP, Perl, Python, Ruby, BASIC C, C++, Pascal

By con­sid­er­ing the dif­fer­ences between compilers and in­ter­pret­ers, you can see their re­spect­ive strengths and weak­nesses when it comes to con­vert­ing source code. Programs with in­ter­pret­ers can be run im­me­di­ately and can thus be started much more quickly. De­vel­op­ment is also much easier than if a compiler were used because the debugging process (i.e. cor­rect­ing errors) is performed with the con­ver­sion line by line. Software using a compiler must first convert all the code before debugging can happen and before the ap­plic­a­tion can be started. However, once the program is running, the compiler is no longer needed, while an in­ter­pret­er will continue to use computing power.

  Advantage Dis­ad­vant­age
In­ter­pret­er simpler de­vel­op­ment process (spe­cific­ally in terms of debugging) in­ef­fi­cient con­ver­sion process and slow execution speed
Compiler Sends the complete ready-to-use ex­ecut­able machine code to the processor any changes made to the code (e.g. debugging, software ex­ten­sions etc.) will require it to be converted again

A hybrid solution combining compilers and in­ter­pret­ers: the just-in-time compiler

There is another model available called the just-in-time compiler which addresses the weak­nesses of each con­ver­sion solution. This special type of compiler, which is sometimes called a compreter (a port­manteau of compiler and interpreter) does not function like normal compilers. It converts the source code during its execution just like in­ter­pret­ers. This results in a sim­pli­fied de­vel­op­ment process in addition to the high execution speed (thanks to the compiler).

Java is one of the best-known examples of a language which relies on just-in-time com­pil­a­tion: As a part of the Java Runtime En­vir­on­ment (JRE), a JIT compiler improves the per­form­ance of Java ap­plic­a­tions by con­vert­ing pre­vi­ously generated bytecode into machine code at runtime.

Go to Main Menu