Compilation
Compilation translates source code into machine code or bytecode ahead of execution, enabling early error checking and optimization at the cost of a build step.
Compilation is the process by which a compiler translates human-readable source code into a lower-level representation that can be executed — typically native machine code for a specific processor, or an intermediate bytecode for a virtual machine. The translation happens ahead of execution, producing an artifact that runs later.
How It Works
A compiler proceeds through stages: lexical analysis breaks source into tokens; parsing builds a syntax tree; semantic analysis checks rules such as types; and code generation emits the target output, often after optimization passes that improve speed and size. Some languages, like C, Go, and Rust, compile directly to native machine code. Others, like Java and C#, compile to bytecode that a virtual machine runs, frequently with just-in-time (JIT) compilation that turns hot bytecode into native code at run time. Static type checking is part of compilation for statically typed languages.
Why It Matters
Compiling ahead of time lets the compiler catch errors early — syntax mistakes and, in typed languages, type errors — before the program ships. It also allows extensive optimization, so compiled programs typically run faster and start quicker than purely interpreted ones, since the translation work is done once rather than repeatedly during execution. The produced binary can be distributed without the source.
The trade-off is a build step that adds time to the development loop and produces platform-specific artifacts, in contrast to interpretation's immediacy.
Related Terms
Interpretation executes source without an ahead-of-time build. Static typing and the type system are enforced during compilation. Compiled runtimes often pair with garbage collection.