Languages
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.
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:
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.
| Situation | Choose | Why |
|---|---|---|
| A finished program being sold or given to many users | Compiler | The executable runs quickly, users need no translator and the source code stays private |
| Testing a section of code you have just written | Interpreter | It stops on the faulty line and a fix can be tried out at once |
| Users must not be able to alter the code | Compiler | Users 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.
OCR GCSE Computer Science · Languages