«There are many advantages to having a statically type-checked
language. These include
providing earlier (and usually more accurate) information on programmer errors,
providing documentation on the interface of components
(e.g., procedures, functions, and packages or modules),
eliminating the need for run-time checks,
which can slow the program execution,
and providing extra information that can be used
in compiler optimization.
One possible disadvantage of static typing is that
because static type checkers are necessarily conservative,
a static type checker for a programming language
may disallow a program that would execute without error.
Thus statically typed programming languages may be less expressive
than dyncamically typed languages »
[TyOOL].
«Type checking
has proved to be very effective in catching a wide class of programming errors,
from the trivial (misspelled identifiers)
to the fairly deep (violations of data structure invariants).
It makes program [sic!] considerably safer, ensuring integrity
of data structures and type-correct interconnection of program components.
Safety is not the only motivation for equipping programming languages
with type systems, however. Another motivation, which came first
historically, is to facilitate the efficient compilation of programs.
Static typing restricts the set of programs to be compiled ...
Also, static typing guarantees certain properties and invariants
on the data manipulated by the program; the compiler can take
advantages of these semantic guarantees to generate better code. ...
»
[TiC].
Efficient compilation, eg.,
integer:floating-point arithmetics,
working with data of different sizes
«...
The Fortran type system introduces a strict separation
between integer numbers and floating-point numbers at compile-time.
The main motivation for this separation, according to Fortran's
designers, was to avoid the difficulties of handling mixed arithmetics
at run-time. Thanks to the type system, the compiler "knows"
when to generate integer arithmetic operations, float-point arithmetic
operations, and conversions between integers and floats.
Since then, this separation has permeated hardware design:
most processor architectures provide separate register sets
and arithmetic units for integers and for floats.
In turn, this architectural bias makes it nearly impossible
to generate efficient numerical code for a language
whose type system does not statically distinguish floating-point
numbers from integers.
Another area where compilers rely heavily on static typing
is the handling of variable-sized data. Different data types
have different natural memory sizes: ...
Precise knowledge of size information is necessary to generate
corect code that allocates and operates over data structures.
This knowledge is usually derived from the static typing information:
the type of the data determines its memory size and layout »
[TiC].
|