Menu

Languages

Choosing a compiler or an interpreter

Choosing between a compiler and an interpreter depends on two things: how far through development the program is, and who will end up running it. Both turn high-level code into machine code, so the choice is about what suits the job, not about what they do.

Finished and being handed out: choose a compiler

A compiler translates the whole program in one go and produces an executable file. That makes it the sensible choice when a finished program will be installed and run by lots of people, because:

  • the executable runs quickly, as translation is already done;
  • users need no translator on their own computer;
  • you hand over only the executable, so your source code stays private and is hard to copy or change.

Still being built and tested: choose an interpreter

An interpreter translates and runs the code one line at a time, so it halts as soon as a line goes wrong and tells you which line the problem is on. You fix that line and run again straight away, with no compiling step in the way, and you can run a program that is only half finished.

For example, a school installs a finished revision quiz on the computers in its study centre. A compiler suits this: the quiz is translated once, the executable is copied onto every machine, and nobody can open it up and rewrite the questions.

SituationChooseWhy
A finished program being sold or given to many usersCompilerThe executable runs quickly, users need no translator and the source code stays private
Testing a section of code you have just writtenInterpreterIt stops on the faulty line and a fix can be tried out at once
Users must not be able to alter the codeCompilerUsers get only the executable, so the source code is never handed over

So ask who is running the program: someone still fixing it wants an interpreter, while someone who just needs it to work wants a compiler.

Practise this