Type system – Understanding strong typing

source code 1

In general, a strongly typed programming language has some strict rules regarding the way in which different types of information may be used and what types may be combined.

Although almost every programming language provides the ability to convert from one type to the other, these capabilities in a strongly typed language are usually (very) limited.

An example of a conversion that is permitted even in the most strongly typed languages, is that of integers to real numbers. This means that it is permissible for whole numbers (integers) and real numbers (reals or doubles) to be used in arithmetic expressions interchangeably.

Examples of strongly typed languages are Java, Pascal, Scala and Haskell.

Sometimes, the following criterion is used: a language is strongly typed if every variable and parameter has an associated type, and this type is known at compile-time.

In this case, C is strongly typed, although you can say that Java and Pascal are strongly typed than C, because C allows more implicit conversions than the other two.

Another (more stringent) definition: a language is strongly typed if type errors are always detected. For this purpose, it is imperative that the types of all the variables and parameters can be used during compile-time or during run-time.

In this case, C is not strongly-typed: the types of unions are not checked in C. Sometimes strong typing is also treated as static typing. In this case, C is strongly typed.

Weak typing

A language that is not strongly typed, is weakly typed. With weak typing the same problem applies as with strong typing : the term is not applied unambiguously, and some languages that are referred to, described as weak by one author are characterized indicated by other authors as strong.

Unlike languages with strong typing, languages with weak typing impose few rules on the programmer when it comes to the way used types and combined.

Usually this means that the compiler (or interpreter) ensures correct conversion from one type to another when necessary (implicit conversion).

An advantage of weak typing is that the compiler or interpreter takes care of converting types , and the programmer does not have to. A disadvantage of weak typing is that the compiler or interpreter is less easy to detect. Possible errors in a program

Weak vsĀ  strong and static vs dynamic.

Although it is dependent on the definition of strong typing , applied apply (if strong typing is not treated as static type) that are the two categories independently of each other. Or a statically or dynamically typed language depends on when type checking takes place.

Or a language strongly or weakly typed depends on the extent to which type checking occurs : the more type checking is done (how severe a language), the stronger it is typed.

About these ads