You are on page 1of 3

Binding and Binding Times

One of the most useful concepts for characterizing various features of programming languages is
the notion of binding and binding time. This is also one of the "recurring themes" of computing,
because these concepts also play important roles in operating systems, databases, and software
engineering.
A binding in a program is an association of an attribute with a program component such as an
identifier or a symbol. For example the data type of the value of a variable is an attribute that is
associated with the variable name. The binding time for an attribute is the time at which the
binding occurs. For example, in C the binding time for a variable type is when the program is
compiled (because the type cannot be changed without changing and recompiling the program),
but the value of the variable is not bound until the program executes (that is, the value of the
variable can change during execution).
Some additional examples of attributes are:
the meaning of a keyword such as if
the operation associated with a symbol such as +
the entity (variable, keyword, etc.) represented by an identifier
the memory location for the value of an identifier
The most common binding times for attributes are (in chronological order):
1. Language definition
2. Language implementation
3. Program translation (compile time)
4. Link edit
5. Load
6. Program execution (run time)
Some attributes and their binding times for C are shown in the table below:
Attribute Binding time
Type of a variable identifier Translation
Value of a variable identifier Execution
General meaning of + Language definition
Specific meaning of + Translation
Meaning of literal (constant) 23 Language definition
Internal representation of literal 23 Language implementation
Specific computation performed by an external function Link edit
Value of a "global" data identifier Execution
Some explanations of these are:
Meaning of +: The general meaning of + was defined (as numerical addition) when the
language was defined. The specific addition operation (float, double, int, etc.), however,
cannot be determined until program translation time, when it becomes bound to the +
symbol used in the operation.
Literal 23: The meaning of literal 23 as the int value representing the number 23 is fixed
at language definition time. However, the actual representation (sequence of bits) for the
int value 23 can vary on different platforms, and it is not bound until the language
implementation (compiler) is performed.
Computation performed by an external function: A function in another program file (i.e.,
an external function) can come from a library or from another compilation. The specific
function that is linked to the function call is not determined until the program modules
are combined by the linkage editor, and in fact different computations could be done by
using different external modules in different link edits.
The fundamental idea behind the notion of binding and binding times for programming
languages is this: if you look at an identifier or symbol in a program, at what time can you say
exactly what each of its attributes is? If you see the identifier "if" or the literal 23 in a C program,
for example, you know that "if" is a keyword that begins an alternation statement, and 23
represents the int number 23, because these things were determined when the language was
defined and cannot be changed. But if you see the identifier "sum" in a program, you have to
have more context (i.e., a translation must be done) to determine whether sum is a variable or a
function name, and what the type is for sum.
Note that we already have seen one important difference between C and ML that can be
expressed in terms of binding time: the value of a nonlocal and nonparameter data identifier
("global"). In C this value can vary at execution time if the value associated with the global
identifier changes, but in ML the value associated with the global identifier becomes fixed when
the function is defined (translation time) (which provides referential transparency).
It is tempting to say that the type of an identifier is bound at translation time in C but at
execution time in ML, but this is not really the case. One problem is that the distinction between
translation and execution becomes blurred in ML. Another is that the tendency is to think of a val
function in ML as analogous to an assignment operation in C, but it actually is more like a C
declaration than an assignment operation. The type of the data value associated with an identifier
becomes fixed in ML when the appropriate val expression is translated (and executed), so there
really is not much difference between C and ML here. Smalltalk is an example of a language in
which type binding does not occur until execution time.
One additional note: we are sometimes tempted to say that a certain binding comes when a
program is written. However, there really is no reason to make this further refinement, because
there are no significant differences between program-writing time and compile time that are of
interest to us.
Note that there is a tradeoff, as usual, when we consider early binding versus late binding in
terms of advantages and disadvantages. Early binding facilitates efficiency of translation and
program execution because fewer decisions have to be made at translation and execution time.
However, the later the binding the more flexibility that there is for the programmer and the
executing program. Although more flexibility doesn't necessarily lead to more efficient
programming, it can often help if it is not misused.

You might also like