Compiled vs Interpreted
Translate once vs translate on the fly
The compiled vs interpreted distinction describes how a programming language's source code gets turned into instructions a computer can execute. In practice, the line between them has blurred significantly.
Compiled
A compiled language uses a compiler to translate the entire source code into machine code (or an intermediate form) before execution. The result is a standalone binary that runs directly on the hardware. Examples include C, C++, Rust, and Go. Compilation catches many errors upfront and produces optimized, fast executables.
Interpreted
An interpreted language uses an interpreter to execute source code line by line at runtime. There's no separate compilation step — the interpreter reads, translates, and runs each statement in real time. Examples include Python, Ruby, JavaScript (traditionally), and PHP. Interpretation offers faster development cycles and greater flexibility.
Key Differences
- **Performance**: Compiled code is generally faster — optimization happens at compile time. - **Development speed**: Interpreted languages offer faster iteration — no compile step needed. - **Error detection**: Compilers catch type errors and syntax issues before runtime. Interpreters catch them during execution. - **Portability**: Compiled binaries are platform-specific. Interpreted code runs anywhere with the interpreter. - **Distribution**: Compiled languages produce standalone executables. Interpreted languages require the runtime. - **The blurry middle**: Java compiles to bytecode, then JIT-compiles at runtime. Python compiles to .pyc files. JavaScript engines use JIT compilation. Most modern languages use a hybrid approach.
When to Use Each
**Choose compiled** when performance is critical (systems programming, game engines, embedded systems), you want standalone binaries, or you benefit from strict compile-time checks. **Choose interpreted** when development speed matters most (scripting, prototyping, web development), you need dynamic features (eval, monkey-patching), or cross-platform portability is key.
Analogy
**Compiled** is like translating a book into another language before publishing — it takes time upfront, but readers get a polished, fast reading experience. **Interpreted** is like having a live translator at a speech — no prep time needed, but there's a slight delay as each sentence gets translated in real time.