DEV Community

Taichi Murai
Taichi Murai

Posted on

Compiler and Interpreter

There are many programming languages in the world, even though computers only understand machine code.
Today, let's take some time to understand how these languages interpret our high-level code.

Interpreter (JavaScript, Python, Ruby etc)

An interpreter translates our code into machine language while it's running.

Pros

  • The source code can be debugged right away, as it processes one statement at a time.
  • It's more memory-efficient than a compiler because it does not generate object code (the binary representation of the source code). Cons
  • The execution time is generally slower than that of a compiler since it translates and runs the code simultaneously.
  • Users of the program need to have the interpreter.

Compiler (C, C++, Java)

A compiler translates our code into machine language before running it.
Pros

  • The execution time is faster than that of an interpreter because the machine language is ready to run.

Cons

  • It generates object code, making it less memory-efficient than an interpreter.
  • Debugging the source code may take longer, as it translates the entire code into machine code each time.

Side Note

Transpiler

A transpiler translates our code into another high-level code, rather than machine language. Babel, one of the well-known JavaScript transpiler, translates ES2015 to ES5 so that more browsers understand the source code.

Top comments (0)