Information Technology Reference
In-Depth Information
we multiply a by 15, this is a legal mathematical operation, provided a is a num-
ber; otherwise a will know that it does not make sense for it to participate in a
multiplication. The type information store in a is there, but we can say that the typ-
ing is dynamic, in the sense that the programmer does not explicitly write the type
of a and a can dynamically change the type of its content during program execution.
Dynamic typing gives great flexibility and a syntax that is closer to the mathematical
notation of our pseudo code language.
Static typing is often said to be very useful for novice programmers. Incompatible
types are quickly detected and reported before the program can be run. Suppose you
hit the s key instead of the a key when writing the statement a=3 . If you do not
introduce a variable s elsewhere, s is not declared with a type, and a typing error is
detected. With dynamic typing nothing about types is known before the program is
run. Incompatible types are detected when operations become illegal, but a writing
error such as s=3 instead of a=3 is not detected; s is as good as any variable
name, and it is brought into play by the assignment. However, as soon as the program
works with a , this variable is now not initialized, and an error will result.
The authors have programmed in languages with both static and dynamic typing.
The conclusion is that the debugging styles are a bit different, but we cannot claim
that one of the approaches generally leads to fewer errors than the other.
6.2.2
Computational Efficiency
Some computer languages are faster than others. For example, the loop over i in
Algorithm 6.4 will be much faster in Fortran and C/C CC than in Maple, Matlab, or
Python, no matter how much we try to optimize the implementation. The reason that
Fortran, C, and C CC are so much faster stems from the fact that these languages
are compiled into machine code . We can classify computer languages as either inter-
preted or compiled . This distinction reflects the potential speed of the language and
is therefore of particular interest in scientific computing. Normally, compiled lan-
guages have static typing, whereas interpreted languages have dynamic typing. Java
is something in between: It has static typing, was originally interpreted, but is being
equipped with compiler techniques.
Fortran, C, and C CC are examples of compiled languages. A compiler trans-
lates the computer program into machine code, i.e., low-level, primitive instructions
tied to the hardware. Since most programs call up functionality in some external
libraries, the machine code of a program must be linked with a machine code ver-
sion of the required libraries. Compilation and linking are normally two distinct
steps. The machine code of the program and the libraries are merged in one file, the
executable . To run the program, you simply write the name of the executable.
Maple, Matlab, and Python are examples of interpreted languages. A program
is read (line by line) by an interpreter that translates statements in the code into
function calls in a library. The translation takes place while the program is running.
Hence, inside a loop the translation of a particular statement is repeated as many
Search WWH ::




Custom Search