What is Dynamic Type Checking?

Compiler DesignProgramming LanguagesComputer Programming

Type checking is the activity of providing that the operands of an operator are of compatible types. A compatible type is one that is legal for the operator or is enabled under language rules to be implicitly modified by compiler-generated code to a legal type. This automatic conversion is known as coercion. If all binding of variables to type is dynamic in a language, thus type checking can virtually continually be completed dynamically. The dynamic type checking is done during program execution.

The dynamic type checking is generally executed by saving a type tag in each data object that expresses the data type of the object. For example, an integer data object can include both the integer value and an integer type tag.

Each operation is then executed to, start with, a type-checking sequence in which the type tag of each argument is examined. The operation is implemented only if the argument types are right alternatively an error is indicated. The operation should also connect the appropriate type tags to its result that subsequent operations can check them i.e., dynamic checking is completed by inserting more code into the program to identify impending errors.

Advantage of Dynamic Type Checking

There are the following advantages of dynamic type checking which are as follows −

  • There is no flexibility in program design.

  • There is no requirement for declarations.

  • The type of data object associated with a variable name can be changed as per need during the program execution.

  • Dynamic type checking can find many errors that cannot be identified by static type checking.

  • In most languages, static type checking is not possible for some language constructs in certain cases but the same purpose can be achieved by dynamic type checking.

Disadvantage of Dynamic Type Checking

There are the following disadvantages of dynamic type checking which are as follows −

  • The dynamic type checking takes up more space as the dynamic type checking involves inserting extra code into the program to detect impending errors.

  • Programs are difficult to debug as all possible execution paths are not explored during program testing.

  • The dynamic type checking takes more time which reduces the speed of executing the operation.

  • It is less efficient than static type checking.

  • It is more expensive.

  • Errors can lurk in a program until they are reached during execution.

  • Large programs tend to have portions that are rarely executed, so a program can be in use for a long time before dynamic type checking detects a type error.

  • Properties that depend on values computed at runtime are rarely checked. For example, imperative languages rarely check that an array index is within bounds.

  • The fundamental hardware does not implement for dynamic type checking.

  • It can manage the tags and increases the complexity.

raja
Updated on 23-Oct-2021 11:08:05

Advertisements