Consider the following pseudocode example:
var x; // (1) x = 5; // (2) x = "hi"; // (3)
In this example, (1) declares the name x; (2) binds the integer value 5 to the name x; and (3) binds the string value "hi" to the name x. A typical static type discipline would require that the name x be assigned a single type, and hence that all values bound to x be of the same type. In such a system, the above code fragment would be illegal, because (2) and (3) bind x to values of inconsistent type (in most type systems, no value can be both an integer and a string). By contrast, a purely dynamically typed system would permit the above program to execute, because the name x would not be required to have a consistent type.
Static type disciplines operate on program source code rather than on the program execution. Therefore, they are able to detect certain kinds of errors without executing the program---this "early detection" of errors is one of the key software engineering benefits of statically typed systems.
The theoretical underpinnings of static typing are given by type theory, an interdisciplinary pursuit that lies at the intersection of mathematical logic and computer science. See type theory for further discussion.
Widely known programming languages with static typing include the following:
Note that some statically typed languages, notably C and its derivatives, have a "back door" in the language that enables programmers to write type-incorrect code by deliberately circumventing the static type system. Languages with back doors are called weakly typed; languages without back doors are called strongly typed.
Also, note that the presence of static typing in a programming language does not necessarily imply the absence of dynamic typing mechanisms. For example, Java is statically typed, but certain operations require the support of runtime type tests, which are a form of dynamic typing. See programming language for more discussion of the interactions between static and dynamic typing.
Search Encyclopedia
|
Featured Article
|