Translating Programs
To make any program, no matter what programming language it was
written in, come alive, it has to be translated into the only thing that our PC
computers can actually execute: machine language instructions. Our pro
grams are all translated from the programming language that the program
mer uses into the machine language that the computer uses. There are three
main ways that this translation is done. They are called interpreting, assem
bling, and compiling. Understanding the basics of each of these three ways
of translating programs is important to us, because it helps us comprehend
what is going on in our computers, and it helps us understand some of the
important limitations of our programs and why some programs run fast and
others quite slow.
Interpreting is a special kind of translation, in which our programs are
essentially translated into machine language on the fly, as the program is
being carried out. It's quite a bit like what's done at international conferences or at the United Nations, where the words of a person speaking are
simultaneously translated into other languages.
Basically what happens when a computer program is interpreted is
this: the program to be interpreted-we'll call it Program-P-is worked
over by an interpreter program, which we'll call Interpreter-I. When we use
Program-P, what happens is that the computer is actually running Inter
preter-I, and Interpreter-I carries out the steps that Program-P calls for.
Interpreter-I scans over the text of Program-P, and step by step, Inter
preter-I performs the work that Program-P says is to be done. In effect,
Interpreter-I is translating Program-P word by word, step by step, and
carrying it out (executing it) on the fly-just the way that simultaneous
translators at the United Nations work.
Interpreting is inherently a slow and inefficient process, but a flexible
one. It's slow because the translation is being done at the same time the
work of the program is being carried out-so time is being taken up per
forming two tasks (translating the program and doing the program's work)
instead of just one. It's inefficient because the translation is done over and
over again-not just each time the program is run, but also each time a step
of the program is repeated. Since much of the power of programs comes
from repeated steps (program looping as it's called) there's plenty of
repeated translation when a program is interpreted. On the other hand,
interpreting is also especially flexible, because an interpreted program can
be adjusted, changed, or revised on the fly. Since the translation of an
interpreted program is done continuously, changes to an interpreted pro
gram can be made on the spot and accommodated immediately.