This content can't be printed from the browser. Use Export PDF with Pro for an offline copy.
IB Syllabus Requirements for Translation
A1.4.1
Evaluating interpreters and compilers
A1.4.1
EVALUATING INTERPRETERS AND COMPILERS
To evaluate a translation process, judge how well it fits a particular application. Look at how translation happens and when errors are detected. Consider the time needed before and during execution, as well as whether the program needs to run on different platforms. No approach is best for every application.
An interpreter translates and executes a program as it runs instead of first producing a complete standalone machine-code executable. A simple source-code interpreter processes instructions as execution reaches them, so it may interpret the instructions in a loop repeatedly.
A compiler translates a program into another representation before that version is executed. With ahead-of-time compilation to native machine code, the result targets a particular processor architecture and operating system.
The distinction concerns when and how translation happens. It doesn't create an absolute division between programming languages: a language can have different implementations, and one implementation can combine compilation with interpretation.
Interpreters allow a short edit–run cycle. A developer can change the source and run it again without a separate whole-program compilation step. The trade-off is overhead from interpreting instructions during execution.
Ahead-of-time compilers take time to translate the program before it runs and can optimize the generated machine code. Repeated execution is often faster as a result, but changing the program means compiling it again. Successful compilation does not prove that a program behaves correctly.
Bytecode is an intermediate instruction representation intended for a virtual machine, not for direct execution by a physical processor. Source code can be compiled into bytecode before the program runs.
A bytecode interpreter uses a compatible virtual machine to execute bytecode instructions. An initial compilation stage is therefore followed by interpretation during execution.
The same bytecode can run on different platforms if each has a compatible virtual machine. That virtual machine supplies the platform-specific implementation, though external libraries and other dependencies must be compatible too.
Just-in-time compilation (JIT) translates code into native machine code while the program is executing. A runtime commonly identifies frequently executed parts and compiles them, then reuses the resulting machine code.
JIT compilation does compilation work during execution in exchange for potentially faster execution afterwards. Long-running programs may benefit substantially. A short-lived program, however, may finish before the benefit outweighs the startup and compilation costs. Even when the distributed bytecode is portable, the generated native code is platform-specific.
Keep Translation time separate from execution time. Translating before execution can reduce the work needed during a run. Moving translation into execution can shorten the initial development cycle, but it can also add runtime overhead.
| Consideration | Source-code interpreter | Ahead-of-time native compiler | Bytecode interpreter | JIT compilation |
|---|---|---|---|---|
| When translation happens | During execution, although some implementations check the source first | Before the executable runs | Source is compiled to bytecode first; bytecode is interpreted during execution | Native compilation happens during execution |
| Error detection | Some errors are reported before execution; others appear only when the affected instructions execute | Syntax errors and other statically detectable errors are reported during compilation | Initial compilation detects some errors; others appear when the virtual machine executes the bytecode | Initial translation or checking detects some errors; runtime errors can still occur during execution |
| Timing trade-off | No separate native compilation stage, but interpretation adds execution overhead | Compilation takes time upfront; native execution is often fast | Initial bytecode compilation plus interpretation overhead during execution | Startup and warm-up costs, with potentially faster execution afterwards |
| Portability | Source needs a suitable interpreter and compatible dependencies | Native executable usually needs rebuilding for a different target platform | Bytecode needs a compatible virtual machine and dependencies | Portable input needs a compatible runtime; native code is generated for the current platform |
| Typical suitability | Frequent changes and short development cycles | Predictable, performance-sensitive execution | Portable distribution where interpretation is sufficiently fast | Frequently repeated work in a long-running application |
Error reporting isn't simply a choice between “all errors before execution” and “one error at a time”. An interpreter may parse the whole program before running it; a compiler may report several errors in a single compilation attempt. Neither guarantees that logical errors will be detected. A program can run successfully and still produce the wrong result, and compiled programs can also encounter runtime errors.
Rapid development and testing. A developer keeps changing the rules in a room-booking prototype. Interpretation is attractive here: changes can be tried immediately, without a separate native build. Compilation, though, can reveal statically detectable errors before a test run. The stronger choice depends on whether fast iteration or early checking matters more. Neither replaces testing.
Performance-critical applications. A controller must repeatedly calculate adjustments within a strict response deadline. Ahead-of-time native compilation avoids interpretation overhead and JIT warm-up during operation, making it attractive for this task. A JIT-based system might deliver strong sustained performance, but compilation pauses make it less suitable when timing must be predictable. Choosing a translation process does not, by itself, guarantee that deadlines will be met.
Cross-platform development. A volunteer scheduling application must run on several operating systems. Distributing bytecode can avoid the need to produce a separate native executable for each platform, provided compatible virtual machines and dependencies are available. A bytecode interpreter favours portability at the cost of execution overhead. With a JIT-enabled runtime, distribution can remain portable while sustained speed improves. Separate native builds are still an option, but each target version must be built and tested.
To justify a decision, connect the application's priorities to the trade-offs. These include development speed and error detection, startup delay versus sustained performance, timing predictability and platform support.
Key terms: interpreter, compiler, error detection, translation time, portability, bytecode, bytecode interpreter, just-in-time compilation (JIT).