Explain the difference between interpreted and compiled programs.
Interpreted and compiled Programs
Explain the difference between interpreted and compiled programs. When you write a shell script, you enter commands like if and while
to instruct the UNIX system what to do. You will be learning more about these commands later in the course.
Before UNIX can use these words, they must be converted into instructions that a computer can understand bits and bytes to be specific, or ones and zeros.
Some programming languages perform this conversion step at the time the program is written.
This conversion process is called compiling the program.
Compiling is performed by a compiler program that reads a text file written in the programming language and converts it into an executable file that can be read efficiently by the operating system.
Languages like C, C++, and assembly language are compiled languages.
Other programming languages are converted as the program is being executed. One instruction at a time is read from the text file containing a script by the interpreter, converted to machine-readable form, and then executed.
The machine-readable form is never stored on disk; it is reconverted each time the program is run. Languages like Perl, Tcl, Python, and all UNIX shell scripting languages are interpreted languages.
Programs written in interpreted languages are generally called scripts. Hence you hear about Perl scripts, Python scripts, and shell scripts. A script is just an interpreted program.
Move your mouse over the following diagram to learn how both kinds of programming languages work.
Advantages of compiled programs versus interpreted:
Key advantages of compiled languages:
Machine-readable files run much faster than a script because the work of conversion is already done.
Data in machine-readable files cannot be deciphered by others. This holds true for C programs that are compiled and generate an executable file that consists of binary code.
This binary code protects trade secrets and intellectual property, which prevents modifications to commercial products.
This page discusses how you can protect your trade secrets by using binary executables.
Key advantages of interpreted languages (scripts):
Because a script does not need to be explicitly compiled before each test run, it is faster to write.
Scripts are more likely to run on a variety of systems because they are distributed as text files and do not rely on special binary formats
like a compiled program does.
Scripts can be read and modified by others to meet their specific needs.
Other interpreted languages that can be used for writing scripts are outlined in the next lesson.
Compiling: Converting a human-readable source code file for a program into a computer-readable file that can be executed.