Thursday, April 5, 2012

Compiler vs. Interpreter


When humans ask the computer to perform a task, they should be able to give orders in the computer’s language, as computers understand only machine language. On the other hand, we use high-level language (programming languages), which cannot be understood by computers.

For that we need to translate between machine language (binary code) and high-level language, here come the two main translation processors, which are compilers and interpreters. There are other computer translators, like decompile which translates from computer language to high-level language, and language translators, which translates between programming languages.

As both compiler and interpreter translates high-level language into machine language, they do it in a difference way. Compilers translates the program code into machine code to produce an executable program, where interpreters do translation at “run-time” line-by-line for the program code into machine language using the interpreter. We can think of compilers as in translating a page of a book, while interpreters are like the person who translates sign language on the fly.

Both compilers and interpreters have advantages and disadvantages, and different needs make programmers go for either compilation or interpretation or a combination of both (like in Java). Some Languages like C, Pascal are compiled, while Perl and Ruby languages are examples for interpreted languages.

Interpreted languages can be categorized into two main categories, full interpreted like scripts and batch files, while the other category needs optimization of the code before interpreting, Minate, J. (2005) a developer said “Shell scripts and batch files stick close to the complete pure definition of interpretation by just executing one line of code at a time. Other interpreted languages do some preprocessing and optimization of the raw code before interpreting them to speed up overall execution.”

One advantage of the Interpreted languages that they are platform independent, as the interpreter is responsible for machine language translation (like Java virtual machine), the code or program can run on any machine that have the interpreter installed.
On the case of JavaScript, we need a browser to run the script, as JavaScript code is text file and is not compiled.

Other advantage is that as the code can be “debugged at run-time” Minate, J. (2005)
Unlike the compiled code where a developer has to wait until the full code it compiled. This advantage makes it easier to find the errors and fix them, and somehow makes interpreted languages easier to learn (by trial and error).

Other than that, as the code got executed at run-time, a the code can be changed, refresh the page (if it’s a web page) then the changes will take effect, no need to reboot the machine or shutdown the application. In compiled languages we have to compile the full code to generate the binary file (executable) and run it again, this cannot be done on the fly.

On the other hand, interpreted languages have some limitations or weaknesses, the most common one is that it is slow execution, which is due the fact that the interpreter reads and executes the program on run-time and the other weakness is that the interpreter is needed every time we need to run the application, on the other hand, a compiler is not needed to run the compiled programs (executable).

Interpreted languages due to their advantages, which can be summarized in platform independent and faster debug time because of to the behavior of the interpreter which translates each line-by-line are used widely. JavaScript for example “is used to create dynamic and interactive web contents” Kindig, A. (2008) as well used for e-commerce and adverting. As an example for that I use application that use JavaScript on daily basis when I use the virtual keyboard for my online banking login.


With low cost computers and more high performance machines we get, we can sacrifice the performance degradation we get by the interpreted language for the flexibility we get from it. Rodriguaz, N et al. (1996) investigated “the use of interpreted languages as a tool for development in distributed systems”, as well do need from users to have customizable applications, they said, “that many programs are split in two part, a kernel and a configuration” Rodriguaz, N et al. (1996) where the kernel part is “written in compiled language and configuration is written in interpreted language” Rodriguaz, N et al. (1996) for flexibility.


Mohannad





References:


Burns, J. (2009)  ‘Java vs. JavaScript’ [Online]. Available from: http://www.htmlgoodies.com/beyond/javascript/article.php/3470971/Java-vs-JavaScript.htm (Accessed 30 January 2011)

Difference Between, (1999). ‘Difference Between Java and JavaScript’ [Online] Available from:


(Accessed 30 January 2011)

Jones, C. ‘Compilers And Interpreters’ [Online] Available from: http://ugweb.cs.ualberta.ca/resources/java/faq/compile.html (Accessed 30 January 2011)


Kindig, A. (2008) ‘What Is JavaScript Used For?’ [Online]. Available from:
(Accessed 30 January 2011)
Luber, J. (2009) ‘The difference between compilers and interpreters’ [Online]. Available from:

Minatel, J. (2005) ‘Term of the week: Interpreted Language’ [Online]. Available from: http://www.developer.com/java/other/article.php/3509911/Term-of-the-Week-Interpreted-Language.htm (Accessed 30 January 2011)

Robat,C. (2005) ‘Interpreters, 2. Introduction to Software History (cont'd)’ [Online]. Available from:
(Accessed 30 January 2011)

Rodriguez, N et al. (1996) ‘The Use of interpreted languages for implementing parallel algorithms on distributed systems’ [Online]. Available from:



Wikipedia, (2011). Interpreter (computing). [Online] Available from: http://en.wikipedia.org/wiki/Interpreter_(computing) (Accessed 30 January 2011)

Wikipedia, (2011), ‘Cross-platform ‘ [Online]. Available from: http://en.wikipedia.org/wiki/Cross-platform (Accessed 30 January 2011)



No comments:

Post a Comment