Compiled vs interpreted programming languages

Compiled

Interpreted

C (1972)

C++ (1985)

Rust (2010)

Go (2009)

Java (1995)

Scala (2004)

JavaScript (1995)

Python (1991)

PHP (1995)

Ruby (1995)

Haskell (1990)

Fortran (1957)

Compiled

#include <iostream>
int main() 
{
  std::cout << "Hello, World!" << std::endl;
  return 0;
}
main:
        push    rbp
        mov     rbp, rsp
        mov     esi, OFFSET FLAT:.LC0
        mov     edi, OFFSET FLAT:_ZSt4cout
		...
01010111101101100111011010101111011011001110110101011
10110110011101101010111101101100111011011101001010110
10101111011011001110111010101111011011001110110101011
11011011001110110101011110110110011101111011011001110
...

C++

Assembly (gcc)

Machine code

Interpreted

console.log("Hello, World!")
[generated bytecode for function:  (0x2487eeea7f51 <SharedFunctionInfo>)]
Parameter count 6
Register count 12
Frame size 96
143 S> 0x2487eeea80ee @    0 : 12 00             LdaConstant [0]
       0x2487eeea80f0 @    2 : 26 f3             Star r8
143 E> 0x2487eeea80f2 @    4 : 5d 05 f3 00       CallUndefinedReceiver1 a1, r8, [0]
       0x2487eeea80f6 @    8 : 26 f4             Star r7
112 S> 0x2487eeea80f8 @   10 : 28 f4 01 02       LdaNamedProperty r7, [1], [2]
       0x2487eeea80fc @   14 : 26 fb             Star r0
...
01010111101101100111011010101111011011001110110101011
10110100111000001010111101101100111011011101001010110
10101111011011001110111010101111011011001110110101011
11011011001110110101011110110110011101111011011001110
...

JavaScript

Bytecode (V8)

Machine code

main:
        push    rbp
        mov     rbp, rsp
        mov     esi, OFFSET FLAT:.LC0
        mov     edi, OFFSET FLAT:_ZSt4cout
		...

JIT segment compilation

Comparison

Compiled

  • Positives
    • Very fast (direct machine instructions for the CPU, ahead of time (AOT) compilation
    • Offers lower-level access to the hardware
  • Negatives
    • Have to compile for multiple architectures you want to run on (x86, arm, etc...)
    • Have to recompile your code after every change

Interpreted

  • Positives
    • Platform independent
  • Negatives
    • Requires the interpreter to available on the machine
    • Slower, but faster nowadays with just in time (JIT) compilation

Bonus: Web Assembly (WASM)

"WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications."

TL;DR

  • You can write C++, Rust or Go and run inside the browser

https://webassembly.org/