A Crash Course in Interpreted vs. Compiled Languages

A Crash Course in Interpreted vs. Compiled Languages

Human speech, regardless of language, engages the same underlying neural machinery when generated in the brain. Stimuli is taken in, the temporal and prefrontal lobes communicate to determine content and phrasing, and the parietal lobe sends messages to your mouth to determine how the words are actually formed. Some linguists believe that languages emerge similarly through a natural process of understanding-development (or so I read on Noam Chomsky?s Wikipedia page).

Programming languages, on the other hand, are heterogenous in both expression and implementation. Like spoken languages, they all have a unique syntax and set of idioms, but they also differ in how their programs are prepared and run (think moving the mouth). The primary area of difference is whether a language is interpreted or compiled.

Interpretation and? compilation?

In the past, there was a relatively cut and dry separation between interpreted and compiled languages.

Speaking simplistically, compiled languages are those which are written in one language and, before being run, translated or ?compiled? into another language, called the target language. Once the translation is complete, the executable code is either run or set aside to run later. Some common compiled languages include C, C++, Delphi and Rust.

Image for postCompiled languages will probably never disappear.

The alternative to using a compiler (for a compiled language) is using an interpreter (for interpreted languages).

Interpreted languages are ?interpreted? live in their original source code, although in reality they are merely compiled at runtime. What this allows for is a lot more flexibility, especially when it comes to a program adaptively modifying its structure. This flexibility does have a cost; interpreted languages are considered significantly slower.

A lot of the languages that we think of as modern, like Ruby, are considered interpreted. Python, Ruby, PHP, and Perl are all interpreted languages.

But Wait? Shouldn?t this be more complex?

Don?t worry ? it is!

The fact is that the interpreted/compiled distinction is actually an arbitrary one ? though certain programs lend themselves better to being interpreted, an ambitious programmer could write a compiler for any generally interpreted language, or vice versa.

Moreover, hybrid systems have emerged that combine elements of both compiled and interpreted languages.

Just-in-time compilation, also known as JIT compilation, is essentially a hybrid of interpreted and compiled languages. The difference between interpretation and JIT compilation, which occurs at runtime, is that the JIT compiler translates source code into native code (machine language), whereas an interpreter either runs code directly (if it is already machine language), runs precompiled code, or turns code into an intermediate language.

Confused? Just wait.

There are other compilation/interpretation hybridization strategies as well. The most common is employing bytecode languages, which fall somewhere between compiled and interpreted languages. In languages like Java and .NET, code is first compiled into bytecode, which is like high-level machine code, and then that bytecode is run through a standard interpreter. Not only that, languages that use bytecode interpretation can also use JIT compilers.

I get it!

Ultimately, the key concepts are that compilers take your high-level language and translate it to a format that your computer can read more quickly. Interpreted languages are allowed to do things like change themselves during runtime, and so they are much more flexible. But slower.

And bytecode is like a compiled interpreted language that then gets compiled by a subroutine and subsequently interpreted. I think.

It?s a lot to handle, which is why I?m going to write another blog post on some really fascinating concepts I didn?t get to address in this post: dynamic languages (dynamic vs static typing), virtual machines, and maybe even some abstract syntax trees are all in the pipeline.

Til? next time!

20