Compiled versus Interpreted Languages

 



Programming languages generally fall into two categories: interpreted and compiled. However, modern innovations and some very intelligent developers have significantly blurred the line between what can be considered an interpreted language and what can be considered a compiled language.



How your computer understands code

Computers only understand low level machine language; also called binary code. Binary code consists of instructions written as 1s and 0s or binary. Understanding and writing computer programs in binary isn't practical for your run-of-the-mill developer and as such, they need a high level language that is human-readable. This is where high level languages come in. 


Therefore, a program is first written in a high level language. Then, a compiler or an interpreter transforms the program's high level language - which a computer does not yet understand - to low level binary code that the computer can then run.


Compilers and interpreters are themselves programs that allow for communication between developers and computers by converting high level languages to low level machine-readable binary. They may perform the aforementioned function in different ways but the end result is always the same.



The recipe analogy

Now, to explain the differences between the mechanisms that underpin compiled and interpreted languages, I will use the recipe analogy:


Imagine for a minute that you want to make ginger biscuits but the only recipe you have is written in Latin. Unfortunately, you only speak English. There are two ways you can get to use your Latin recipe. The first involves a friend who speaks Latin fully translating the recipe for you into English and thus allowing you to use it. If one instruction or ingredient changes in the recipe, your friend will have to provide a brand new full translation of the recipe to account for the changes that have occurred.


Another way is for your bilingual friend to interpret the Latin instructions step-by-step for you as you make the ginger biscuits. This will be slower than having the full set of English instructions but if anything in the recipe were to change, there's no need to translate the whole recipe from scratch.


In compiled languages, high level programs are compiled beforehand into low level machine-readable equivalents before they are executed/ran. That is, compilers play the same role that your English speaking friend plays by fully translating the recipe for you beforehand.


For interpreted languages, an interpreter goes through each line of a high level program's source code and converts it into machine-readable code as the program runs. Interpreters play the same role that your bilingual friend would if they translated each instruction in the recipe step-by-step.



Compiled languages

Examples of compiled languages include GO, C, C++, COBOL and many others.

The greatest advantage that compiled languages have over their interpreted counterparts is speed. Since compilation only occurs once and machine language runs very fast due to its native nature, compiled languages are generally faster and more efficient.


However, compilation to native machine language means that a compiled program can only run on a computer on which it as been compiled. This is due to the specificity that system architecture and hardware add to machine language. Thus, compiled programs only run on the computers on which they have been compiled or those with similar architecture. 



Interpreted languages

JavaScript and Python are by far the most popular members of the interpreted languages club. The most compelling advantage to these languages is that they can run on any system with an interpreter. This is due to the fact that high level language code acts as the source code for an interpreted program and is ran as is without a compilation step.


The main disadvantage associated with interpreted languages is their relative sluggishness when compared to their compiled brethren. Sluggish performance is however quickly becoming a thing of the past thanks to the rise of Just-In-Time compilation or JIT which warrants an independent blog post...

Comments

Popular posts from this blog

How your VPN works

The Mouse on Your Desk

Why you need a Password Manager right now