Strong typing

From DmWiki

Strong typing is a feature of a programming language in which variables must be declared and given a type (such as integer, string, array, or more complex types) before they can be used. Its opposite is weak typing.

C++ and most other compiled languages (including Pascal and Java) are strongly typed. For example, the C++ code

int a;
std::string b;

declares two variables, one called a of type int (shorthand for integer), and one called b of type std::string (which means "standard string"). Strong typing allows the language compiler to catch many errors at compile-time by the process of type checking; for instance, a statement like

a = b;

would not be permitted with the above declarations, since it makes no sense to try to assign a string to an integer. Strong typing also allows the compiler to calculate in advance exactly how much memory will be needed for each variable, allowing more efficient memory use and better performance than a weakly typed language (also called a scripting language). However, modern computers are powerful enough that this efficiency difference is noticeable only for very large programs.


DevMaster navigation