Type binding comparision

The concept of binding and type binding

In general case, binding is an association, such as between an attribute and an entity or between an operation an a symbol – Concept of programming language 9th Edition. A binding can take place at language design time, language implement time, compile time, load time, link time or run time. We call the time when the binding takes place is binding time.

Before referencing a variable, the variable must be bound to a data type – what we call a type binding. Base on the binding time and how the type is specified, we have some kinds of type binding:

  • Static binding: the binding first occurs before run time and remains unchanged through the program execution. There are two type of static binding:Explicit static binding: the programming language set the type of a variable by using some statement which list variable names and specify that they are a particular type.

    Implicit static binding: the variable type is set by a default convention instead of a declaration statement.

  • Dynamic binding: the type of a variable is specified in an assignment statement. It can be changed during the program life.

Static binding: explicit vs. implicit

Explicit static bindingImplicit static binding
reduce the reliability: prevent the compilation process from detecting programmer errors
A namespace can be used to avoid some disadvantages. The name of a specific type must begin with a particular special character.
Some languagesMost programming languages designed since the mid-1960s (except Perl, JavaScript, Ruby an ML)Fortran (when not explicitly declared), BASIC

Static binding vs. dynamic binding

Static bindingDynamic binding
Cannot process data without knowing the data typeProvide more programming flexibility: we can write a program working with a variable even when we have not known its type yet.
The compiler can detect the fault in type binding time. However, some languages such as Fortran, C/C++ which have some rules to automatically convert the type of the RHS to the type of type of the LHS have the same disadvantage as using dynamic bindingReduce the reliability: the error detection capability of the compiler is diminished. Incorrect type of the right side of an assignment is not detected as an error; rather, the left side is converted to the incorrect type.
The cost of implementationThe type checking ran before the run rime, so there is no cost of type checking in the program execution.The type checking must be done at run time, which requires the variable must have a addition descriptor and makes the storage used for a variable must be variable
Usually use complierUsually use interpreter due to the difficulty of building machine code without knowing the type of operants
Some languagesC/C++, Java, Pascal, Fortran, BASICJavaScript, PHP, Python

Leave a Reply