Sunday, 16 December 2007

Interpreted vs Compiled Code

Interpreted code executes much more slowly than compiled code, yet several systems use them extensively. The most well known are Visual Basic (it has two modes: interpreter mode and compiler mode) and JavaScript. Discuss the merits and weaknesses of interpreting, as opposed to compiling, and explain when and why they are used.

The major advantage of interpreted languages is the platform independence that they offer. The best example of this is JavaScript. Rather than forcing the user of a computer to install every single application that they wanted to use, applications written using JavaScript can be delivered through a web browser which installs all the necessary files (in reality downloading them to a temporary folder) without the user knowing anything about it. This means that applications can be easily made available to any operating system(such as Windows, Linux and Mac OS) that supports a web browser. The platform independence is one of the main reasons for the rapidly increasing popularity of using thin client web - based applications rather than thick - client desktop applications. Without interpreted JavaScript I would have to install one application to use Google Mail, another to use Expedia, another to use (of course these websites probably wouldn't exist at all but you get the idea).

A second advantage is speed in which interpreted languages can be developed in. When working with JavaScript, for example, a programmer can embed some code inside a tag within some HTML and, assuming that they have the Java Virtual Machine installed, open the web page in a browser and see the results straight away. The developer can quickly change some aspect of the code, refresh the browser and the change will be instantly reflected. Contrast this with compiler language development. The coder must change their code and then run it through a compiler with the necessary parameters to produce a compiled assembly such as a Dynamic Link Library (DLL). The DLL must then be deployed to the correct location (perhaps another development server, and in fact this deployment can sometimes require another step because in a Windows environment all assemblies must be manually deployed to the General Assembly Cache) and finally the assembly must be executed by a program.

One of the most commonly cited reasons for using a compiled language rather than an interpreted language is speed - because an interpreted language has to be compiled each and every time it is run it creates an extra overhead. But in reality most modern web applications use a combination of interpreted and compiled code. For example, an e-commerce website is likely to use some embedded JavaScript to perform simple functionality at the client side such as validating the data inside a TextBox. This will create a small overhead in terms of needing to compile the code at every run time, but the tiny amount of code required to do this makes the overhead pretty neglibible. The more error - prone parts of the website - such as interacting with a database to store data or perform complicated searches - are likely to be performed by pre-compiled web services or stored procedures / functions on the database server itself. The IBM Information Centre states "we can see that it would make sense to use a compiled language for the intensive parts of an application (heavy resource usage), whereas interfaces (invoking the application) and less-intensive parts could be written in an interpreted language" (2007).


IBM Corporation (2007) Compiled versus interpreted languages [Online] IBM Corporation, NY, USA
Available from (Accessed 16th Dec 2007)

No comments: