Section 1.1.2

Compilation vs Interpretation

For a program to run on a computer the source code needs to be converted to machine code. There are 2 ways this could take place:

Compilation

The source code is compiled into a stand-alone executable file (.exe for Windows or .app for Mac). This executable is compiled for 1 platform only and requires the code to be re-compiled if it needs to run on a different operating system. Any changes to the source code results in the code needing to be compiled again before being executed which is very time-consuming.

Interpretation

The source code is interpreted line by line by an interpreter installed on the target computer. The source code can usually then be executed on multiple platforms once the interpreter has been installed on that platform. Any changes made to the source code can be seen immediately when the code is executed by the interpreter. With this scenario, writing the code can be done on a Windows OS and the source code could then be executed on a MacOS or a Linux based computer without modification.

How does an Interpreter Work?

A source code file is a basic text file containing instructions that appear in the computer language that the file is written for. When executed, the interpreter reads this file line by line from top to bottom carrying out the instructions that exist on each line. If the interpreter encounters an error in the code it halts execution and displays a corresponding error message. If the code has no errors, then the program ends when the last line has been executed. This model obeys the following sequence on each line of code:

read - interpret/check - execute

What does this mean for us?

Python is the language used in this course. It is an interpreted language which means that in order to execute the code written, a suitable interpreter need to be installed on your computer. Fortunately python is free and can be downloaded and installed on any computer platform.

You can find it here python.org

Python code is written in text files called scripts and for this reason it is sometimes referred to as a scripting language.



list of sections  previous <<  home  >> next