20 juillet 2018
We need a translator (compiler or interpreter) to go from source to binary code.
|The Compiler||The Interpreter|
|Input||takes the entire program and translates it as a whole into machine code.||takes one statement at a time.|
|Workload||runs once and only needs to be called again for re-translation.||runs each time the code needs to be executed.|
|Errors||generates the error message only after scanning the whole program: debugging is hard.||continues translating the program until the first error is met, in which case it stops: debugging is easy.|
|Sharing||harder to share: binary may not be read by different OS, source code must be re-compiled.||easy to share: just pass the source code.|
Because at "compile time", the compiler needs to know exactly what objects are, use of variables is less flexible:
int x; // Construction: allocate // memory to the object. x = 15; // Initialisation of // the object. x = x + 1; // Do stuff. ~x; // Destruction: clear memory. // Usually implicit.