Compiler or Interpreter?

Cards (5)

  • The question of whether to use a compiler or an interpreter depends on the programming language in use. For example, Java programs must be compiled, whereas PHP programs (used to create dynamic web pages) are interpreted. When choosing between a programming language that can be compiled or one that can be interpreted, the programmer should consider the benefits and drawbacks of each technique.
  • Compiler benefits

    • Code can be well optimised by the compiler
    • Compiled programs can be distributed as machine code, meaning that the source code is hidden and can be kept secret for commercial reasons
    • No translation is required at execution time, as it has already been done (when the source code was compiled)
  • Compiler Drawbacks

    • You have to wait until the entire program is compiled before receiving any errors, which for a large program may take some time
    • If you want to change something in the program, you have to recompile the entire program
    • The executable code produced is specific to the processor platform
  • Interpreter Benefits
    • Errors will be reported as soon as they are encountered, which means that you don't have to wait for the entire program to be compiled
    • Errors are shown line by line as the interpreter reaches them
    • Debugging is quicker and easier as errors are reported in the console, which shows what and where the error is in the code
  • Interpreter Drawbacks
    • The program requires an interpreter to be run
    • Translating the code line by line at execution time is slower than running compiled machine code
    • The interpreter takes up space in memory