Strongly-typed programming language
From Freepedia
In computer science and computer programming, the term strong typing is used to describe how programming languages handle datatypes. The antonym is weak typing. However, these terms have been given such a wide variety of meanings over the short history of computing that it is often difficult to know what an individual writer means by using them.
Programming language expert Benjamin C. Pierce has said:
- I spent a few weeks . . . trying to sort out the terminology of "strongly typed," "statically typed," "safe," etc., and found it amazingly difficult. . . . The usage of these terms is so various as to render them almost useless.
Most generally, "strong typing" implies that the programming language or implementation enforces some kind of constraints upon programs, preventing them from running code which uses data in an invalid way. For instance, an integer addition operation may not be used upon strings; a procedure which operates upon linked lists may not be used upon numbers. However, the nature and strength of these constraints is highly variable.
Some of the things which writers have described as "strong typing" include:
- Static typing as opposed to dynamic typing. In a static type system, type annotations are associated with variable names rather than values. It is thus possible for the compiler to prove via static analysis that a program contains no type errors.
- The mandatory presence of compile-time checks for type constraint violations. That is, the compiler actually does perform static analysis, and rejects programs which fail it.
- Type safety; that is, the rejection (at either compile or run time) of operations or function calls which attempt to disregard data types.
- The disallowing of type conversion. Variables or values of one type may not be used in the place of those of a related type. Integers and floating point numbers, for instance, may be held strictly separate.
- The disallowing of implicit type conversion. Types must be converted by an explicit notation such as a function that accepts one type and returns a different one.
- The absence of ways to evade the type system. C-style casts, or the ability to use a pointer to one type as if it had contained a different type, are disallowed.
- A complex, fine-grained type system with compound types.
- The assignment of a fixed an invariable type to data objects. The type of a given data object does not vary over that object's lifetime. Class instances, for example, may not have their class altered.
- Strong guarantees about the run-time behavior of a program before program execution, whether provided by static analysis or another mechanism.
Note that some of these definitions are contradictory, while others are merely orthogonal. Because of the wide divergence among these definitions, it is possible to defend claims about most programming languages that they are either strongly- or weakly-typed. For instance:
- C compilers perform static analysis about many - but not all - classes of variables, but permit the programmer to easily override the type system using casts.
- Perl clearly assigns a type to every variable (denoted by the "funny character" in the variable name) but performs implicit conversions readily, for instance between numbers and strings of numerals.
- Common Lisp has a complex, fine-grained system of data types, but is almost entirely dynamically typed.
For this reason, writers who wish to write unambiguously about type systems often eschew the term "strong typing" in favor of specific expressions such as "static typing" or "type safety".
For a more thorough discussion of typing issues, see the article on datatypes and its related topics.



