Wörterbuch

Type Checking

Moderate

A process in programming languages to verify whether or not each operation in the program is in accordance with the type declaration rules of the language.

What Is Type Checking?

Type checking is usually performed by a compiler that verifies that all operations have received a proper number of arguments and data types. There are two types of systems, namely:

Static Type Checking

In static type checking, there is no need to run a program to check it. The compiler performs static type checking at compile time. 

Static type checking is useful when there are errors in your program as they can be detected before running it. It helps in improving reliability and security. 

An example for static type checking is C language, where you have to declare variables before using them in your program. If you don't declare them, then the compiler will show an error, and you will not be able to execute your program.

Dynamic Type Checking

Dynamic type checking does not occur until runtime or execution time. Dynamic type checking is useful as it allows us to write programs without prior knowledge about types. In scenarios where we need to check types at runtime only.

The most common form of type checking involves assigning a data type to each variable, parameter and function return value in a computer program. Based on the types assigned to these values, the appropriate operations are allowed (e.g., adding two integer variables to produce another integer or concatenating two strings to produce another string). Type checking ensures that these operations are valid for their intended purposes.

In some programming languages (for example C), type-checking is performed by the compiler; in others (for example PHP), it can be deferred until run time (in which case it may be called dynamic type checking).

Some languages allow the programmer to define new types, so that their programs can use those types in their algorithms. Other languages allow the programmer to associate arbitrary properties with values at run time.

Many languages involve both approaches; for example, Java provides pre-defined types and allows programmers to create new classes or extend existing ones (i.e., define new types). Some languages, such as Perl and Python, also perform type inference and do not require any type declarations.