NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS
Name Binding and Binding Time
Name binding is the associa on of objects (data and/or code) with names (iden fiers) Shape S = new Shape(); The binding of a program element to a par cular property is the choice of the property from a set of possible proper es binding and binding mes are the proper es of program elements that are determined by the defini on of the language or its implementa on The me during program formula on or processing when this choice is made is the binding me There are many classes of bindings in programming languages as well as many different binding mes Binding Time
Binding mes: Run me (execu on me): On entry to a subprogram or block Binding of formal to actual parameters Binding of formal parameters to storage loca ons At arbitrary points during execu on binding of variables to values Dynamic binding
Binding Time
Compile me (Sta c Time) Declara ons (programmer ac on) Variable names variable types program statement structure Compiler ac on Rela ve loca on of data objects Linker ac ons Rela ve loca on of different object modules Binding Time
Binding Time Binding Time o The sum operator (+) At compila on me (depending on the type of the operands because of overloading) o If x is declared integer + means one thing o if x is declared real means something else o + can also be overloaded by the programmer.
o Example (C++): it is possible to specify that + operates on strings: string operator +(string& a, string& b) { return a.append(b); }
Binding Time
Shape s= new Shape(); s.getArea(); // The compiler can resolve this method call statically. Binding Time
public void MakeSomeFoo(object a) { // Things happen... ((Shape) a).getArea(); // You won't know if this works until runtime!}
Binding Time: discussion
• Many of the most important and subtle differences between programming languages involve differences in binding me • The trade off is between sta c analysis, efficient execu on and flexibility • The language comes with a type system. The compiler assigns a type expression to parts of the source program. The compiler checks that the type usage in the program conforms to the type system for the language. • When efficiency is a considera on (Fortran, C) languages are designed so that as many bindings as possible are performed during transla on • Where flexibility is the prime determiner, bindings are delayed un l execu on me so that they may be made data dependent Dynamic Dispatch