- Published on
KembaraXtra-Computer Science - Compiled vs. Interpreted Languages
I. Core Concepts
I. Core Concepts
- Source Code: Human-readable program instructions written by developers.
- Machine Language: Instructions that a CPU can directly execute.
- Compilation: The process of translating source code into machine code (or an intermediate form).
- Interpretation: The process of reading and executing source code instructions line by line (or bytecode).
- Definition: Languages where source code is converted into machine code before runtime.
- Process:
- Developer writes source code (e.g., in C).
- Compiler translates the source code into an executable file (binary).
- End user runs the executable file directly.
- Example: C (using gcc compiler)
- Advantages:
- Fast execution speed because the code is already in machine language.
- Disadvantages:
- Platform-dependent: Executables are specific to the architecture they were compiled for.
- Requires a compilation step during development.
- Definition: Languages where source code is executed line by line by an interpreter during runtime.
- Process:
- Developer writes source code (e.g., in Python).
- End user runs the source code using an interpreter.
- The interpreter reads and executes the code.
- Example: Python
- Advantages:
- Platform-independent: As long as an interpreter exists for a platform, the code can run.
- No compilation step required for the end user.
- Disadvantages:
- Slower execution speed due to the overhead of interpretation.
- Requires the user to have an appropriate interpreter installed.
- Definition: A combination of compilation and interpretation, using an intermediate language called bytecode.
- Process:
- Developer writes source code.
- Compiler translates source code into bytecode.
- A virtual machine (VM) executes the bytecode.
- Bytecode:
- Similar to machine code but designed for a virtual machine, not a specific CPU.
- Virtual Machine (VM):
- A software platform that provides a virtual CPU and execution environment.
- Abstracts away the details of the underlying hardware and OS.
- Examples:
- Java (Java bytecode runs on the Java Virtual Machine - JVM).
- C# (CIL or Common Intermediate Language runs on the .NET Common Language Runtime - CLR).
- Python (CPython implementation compiles to bytecode internally).
- Advantages:
- Combines platform independence (like interpreted languages) with some of the performance benefits of compiled code.
- Disadvantages:
- Still requires a VM to run.
- Execution is generally slower than native compiled code.
0 Comments