TECHNOLOGY 

Published on
KembaraXtra-Computer Science - Compiled vs. Interpreted Languages
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).
II. Compiled Languages
  • Definition: Languages where source code is converted into machine code before runtime.
  • Process:
    1. Developer writes source code (e.g., in C).
    2. Compiler translates the source code into an executable file (binary).
    3. 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.
III. Interpreted Languages
  • Definition: Languages where source code is executed line by line by an interpreter during runtime.
  • Process:
    1. Developer writes source code (e.g., in Python).
    2. End user runs the source code using an interpreter.
    3. 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.
IV. Hybrid Approach: Bytecode
  • Definition: A combination of compilation and interpretation, using an intermediate language called bytecode.
  • Process:
    1. Developer writes source code.
    2. Compiler translates source code into bytecode.
    3. 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.
Picture
0 Comments