Friday, September 10, 2010

Compiler VS Interpreter

As human of course we are prefer to write/create a computer program in human's understandable languages instead of machine languages. 
From here we need a method to convert our "human languages" into machine languages that computer understand well, so we need either Compiler or Interpreter to be done on this.


A lot of the programmer still unable to make a differential or unclear between Compiler VS Interpreter, so let me explain about details based-on my knowledge & experience!


Compiler:
- Reads the entire program source code then only will translate it into whole set of machine code as well as generated a new separate binary code program file such as EXE file in order to perform specify required tasks.
- Execution time will be much faster since entire program has been translated to machine language.
- Code modification needs to make a compilation of the changed source codes and links to entire binary code program before the program able to be executed.
- The compiled Binary code program able to distribute directly to other user's client machine for execution without further translation.
- No need additional software for execution on user's client machine.
- Example Languages: C, C++, Visual Basic and etc.


Interpreter:
- Reads the program source code one instruction by one instruction or so called line by line at a time and translated this line into machine language for immediate execution. The machine language will be discarded once the new next line is  translated and never compiled to new program entity.
- Execution time will be much slower since make source translation during run-time, every line has to be converted per each time the program is runs.
- Code modification just needs to translate to an intermediate representation not translate all, this often makes interpreter languages is more easier to be learned & get the bugs.
- Program source code needs to be distributed for further translation in every single final machine so it will takes more time but it is independent to the machine's architecture.
- Additional interpreter software need to be presented on machine for running the program.
- Example Languages: PHP, Javascript, Forth and etc.

No comments:

Post a Comment