Google

Wednesday, April 2, 2008

Weak and strong typing

Weak typing allows a value of one type to be treated as another, for example treating a string as a number.[14] This can occasionally be useful, but it can also allow some kinds of program faults to go undetected at compile time.

Strong typing prevents the above. Attempting to mix types raises an error.[14] Strongly-typed languages are often termed type-safe or safe. Type safety can prevent particular kinds of program faults occurring (because constructs containing them are flagged at compile time).

An alternative definition for "weakly typed" refers to languages, such as Perl, JavaScript, and C++ which permit a large number of implicit type conversions; Perl in particular can be characterized as a dynamically typed programming language in which type checking can take place at runtime. See type system. This capability is often useful, but occasionally dangerous; as it would permit operations whose objects can change type on demand.

Strong and static are generally considered orthogonal concepts, but usage in the literature differs. Some use the term strongly typed to mean strongly, statically typed, or, even more confusingly, to mean simply statically typed. Thus C has been called both strongly typed and weakly, statically typed.

No comments: