[Home](https://codefionn.eu/) · [About](https://codefionn.eu/about/) · [GitHub](https://github.com/codefionn)

---

# What's the difference between compilers and interpreters?

> What's actually the difference between compilers and interpreters? And why is it difficult to define?

*Published on 2023-04-22 · [View as HTML](https://codefionn.eu/whats-the-difference-between-compilers-and-interpreters/)*

---


This blog post will explain what compilers are and what interpreters are. Then
the differences are outlined and why there's a blurry line between them.

For more information about some of the terms used here, go to my
<a href="/compiler-and-interpreter-lexicon/">compiler and interpreter lexicon</a>.

## What's a compiler?

A compiler transforms code into a different or even the same kind of code.
Typically, compilers are defined by transforming human-readable source code
into machine readable code.

Examples for compilers are GCC, clang, javac or the TypeScript compiler. Even a
<abbr title="ECMAScript">JavaScript</abbr> minifier could be defined as a
compiler.

I personally would define something as a compiler, if it has deeper knowledge
about the input code and the output is a different kind of code, that
semantically does the same thing.

## What's an interpreter?

An interpreter executes code immediatly. Technically, a virtual machine
executing bytecode could also be counted as an interpreter. Though, typically
the input is expected to be high-level, human-readable code.

Examples for interpreters are <abbr title="JavaScript">V8</abbr>,
<abbr title="Python">CPython</abbr> or technically the
<abbr title="Java virtual machine">JVM</abbr>.

## So what's the difference?

The typically definition is that a compiler transforms code into machine code,
that will be executed later, and interpreters execute code immediatly.

A compiler doesn't execute code, that mutates the runtime or the system, an
interpreter does.

## And why is that so hard to define today?

Interpreters like <abbr title="JavaScript">V8</abbr> can compile the code into
bytecode or machine code, so that the execution of the code is faster (this is called
<abbr title="Just-in-time">JIT</abbr> compilation).
See
<a rel="noopener noreferrer" href="https://blog.logrocket.com/how-javascript-works-optimizing-the-v8-compiler-for-efficiency/">
  How JavaScript works: Optimizing the V8 compiler for efficiency
</a> for more information.

Likewise, compilers can execute code at runtime see
<a rel="noopener noreferrer" href="https://en.cppreference.com/w/cpp/language/constexpr">
  constexpr in C++.
</a>

Rust (or Cargo for that matter) can even execute not-constant-code at compile time, see
<a rel="noopener noreferrer" href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">
  Build Scripts
</a> or
<a rel="noopener noreferrer" href="https://doc.rust-lang.org/proc_macro/">
  proc_macro.
</a>

---

[Impressum](https://codefionn.eu/impressum/) · [Datenschutzerklärung](https://codefionn.eu/datenschutz/) · [Mastodon](https://c.im/@codefionn)

© Copyright 2022-2026 Fionn Langhans
