๐งฉ Interpreter vs Compiler
- Source code stays in high-level form (sometimes pre-tokenized into intermediate bytecode).
- Interpreter reads one chunk at a time โ translates to machine instructions โ executes immediately.
- Execution largely follows source order, so fewer global optimizations.
- Structure remains close to original source, making reverse-engineering easier.
Compiler Flow
- Reads the entire source before execution.
- Builds an Abstract Syntax Tree (AST) and performs multiple analysis/optimization passes.
- Emits a platform-specific machine code binary (or VM bytecode).
- Can reorder instructions, inline functions, unroll loops, and strip dead code โ final binary may differ greatly from source order for performance.
๐ Key Takeaway
- Interpreter โ Portability & immediacy (no build step, same source runs anywhere with the right runtime).
- Compiler โ Performance & optimization (cost: platformโspecific binaries and a compile step).
๐ Compiled vs Interpreted in Terms of Portability
| Feature | Compiled Program | Interpreted Program |
|---|---|---|
| How it runs | Source โ compiler โ machine code specific to CPU/OS | Source stays highโlevel, run by an interpreter |
| Portability | Must recompile for each target platform | Same source runs anywhere with correct interpreter |
| Dependencies | No interpreter needed โ just the compiled binary | Interpreter required |
| Performance | Very fast after compilation | Slower โ runtime translation overhead |
๐ก Summary
Highโlevel languages trade raw execution speed for:
- Developer productivity
- Maintainability
- Portability
- Safety
Last updated on