The implementation of a dynamically typed language will catch errors related to the misuse of values---"type errors"---at the time the erroneous statement or expression is computed. In other words, dynamic typing catches errors during program execution. A typical implementation of dynamic typing will keep all program values "tagged" with a type, and checking the type tag before any value is used in an operation.
For example, consider the following pseudocode:
var x = 5; // (1) var y = "hi"; // (2) x + y; // (3)
In this code fragment, (1) binds the value 5 to x; (2) binds the value "hi" to y; and (3) attempts to add x to y. In a dynamically typed language implementation, the value bound to x might be a pair (integer, 5), and the value bound to y might be a pair (string, "hi"). When the program attempts to execute line (3), the language implementation would check the type tags integer and string, discover that the operation + (addition) is not defined over these two types, and signal an error.
Dynamic typing sometimes simplifies the task of writing code, because it allows the programmer to write code that would be illegal in some static type systems. Also, certain language constructs (for example, an eval function that can execute arbitrary data as code) are difficult to provide in a purely statically typed language.
However, purely dynamically typed languages provide only "late detection" of errors---errors may not be detected until the program is actually run. This complicates both the task of verifying that code is correct a priori, and the task of debugging code a posteriori when errors do arise. Dynamic typing advocates claim that the benefits of flexibility outweigh these disadvantages.
Well-known dynamically typed languages, in each of the major language paradigms, include the following:
Other dynamically typed languages include:
Search Encyclopedia
|
Featured Article
|