The concept of a "type" is really a human concept, over and above anything that corresponds to any physical implementation. When a programmer says that a variable is of type color
, with values such as red
, green
, and blue
, he is trying to describe a constraint that can be detected and therefore enforced by the programming language. He really doesn't care that the physical implementation consists of integers ... he's saying that the variable "is a" color
, and he wants the language to enforce that.
For example, the statement i = red
can be objectively recognized to be an error if "the type of" i
is not color
. In other words, "the programming language found this bug for you." (Whereas, you, poring through mountains of source-code, probably never would. "Being a digital computer has its advantages ...")
Static typing takes place "at compile time." If you violate one of these rules, your program "doesn't compile."
Dynamic typing relies upon at-runtime checks, which are probably performed by a language interpreter. Purely-interpreted languages have no concept of "compile time," and support situations that are entirely transient ... possibly created by [vast quantities of ...] source-code that your program knows nothing of. Dynamic typing is the only mechanism that such languages can use. Type-related checks occur constantly at runtime, and this overhead is judged to be acceptable.