Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Name binding
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Association of data/code with identifiers in programming languages}} {{for|bound variables in mathematics|free variables and bound variables}} In [[programming language]]s, '''name binding''' is the association of entities (data and/or code) with [[identifier]]s.<ref name=tkac08>{{Citation |title=Using early binding and late binding in Automation |author=Microsoft |url=http://support.microsoft.com/kb/245115 |publisher=Microsoft |date=May 11, 2007 |access-date=May 11, 2009}}</ref> An identifier bound to an [[Object (computer science)|object]] is said to [[Reference (computer science)|reference]] that object. [[Machine language]]s have no built-in notion of identifiers, but name-object bindings as a service and notation for the programmer is implemented by programming languages. Binding is intimately connected with [[scoping]], as scope determines which names bind to which objects – at which locations in the program code ([[Scope (computer science)#Lexical_scoping|lexically]]) and in which one of the possible execution paths ([[Scope (computer science)#Dynamic_scoping|temporally]]). Use of an identifier {{mono|id}} in a context that establishes a binding for {{mono|id}} is called a binding (or defining) occurrence. In all other occurrences (e.g., in [[Expression (computer science)|expressions]], [[Assignment (computer science)|assignments]], and [[subprogram]] calls), an identifier stands for what it is bound to; such occurrences are called applied occurrences. ==Binding time== * ''Static binding'' (or ''early binding'') is name binding performed before the program is run.<ref name=ieee24765:2010(E)>{{Citation |title=Systems and software engineering — Vocabulary ISO/IEC/IEEE 24765:2010(E)|publisher=IEEE |date=Dec 15, 2010}}</ref> * ''Dynamic binding'' (or ''[[late binding]]'' or ''virtual binding'') is name binding performed as the program is running.<ref name=ieee24765:2010(E) /> An example of a static binding is a direct [[C (programming language)|C]] function call: the function referenced by the identifier cannot change at runtime. An example of dynamic binding is [[dynamic dispatch]], as in a [[C++]] virtual method call. Since the specific type of a [[Polymorphism (computer science)|polymorphic]] object is not known before runtime (in general), the executed function is dynamically bound. Take, for example, the following [[Java (programming language)|Java]] code: <syntaxhighlight lang="java"> public void foo(java.util.List<String> list) { list.add("bar"); } </syntaxhighlight> <code>List</code> is an [[interface (computing)|interface]], so <code>list</code> must refer to a [[Subtyping|subtype]] of it. <code>list</code> may reference a <code>LinkedList</code>, an <code>ArrayList</code>, or some other [[Subtyping|subtype]] of <code>List</code>. The method referenced by <code>add</code> is not known until runtime. In C, which does not have dynamic binding, a similar goal may be achieved by a call to a function pointed to by a variable or expression of a [[function pointer]] type, whose value is unknown until it is evaluated at run-time. ==Rebinding and mutation== Rebinding should not be confused with mutation or assignment. * ''Rebinding'' is a change to the ''referencing'' identifier. * ''Assignment'' is a change to (the referenced) variable. * ''Mutation'' is a change to an object in memory, possibly referenced by a variable or bound to an identifier. Consider the following [[Java (programming language)|Java]] code: <syntaxhighlight lang="java"> LinkedList<String> list; list = new LinkedList<String>(); list.add("foo"); list = null; { LinkedList<Integer> list = new LinkedList<Integer>(); list.add(Integer(2)); } </syntaxhighlight> The identifier <code>list</code> is bound to a variable in the first line; in the second, an object (a linked list of strings) is assigned to the variable. The linked list referenced by the variable is then mutated, adding a string to the list. Next, the variable is assigned the constant <code>null</code>. In the last line, the identifier is rebound for the scope of the block. Operations within the block access a new variable and not the variable previously bound to <code>list</code>. ==Late static== Late static binding is a variant of binding somewhere between static and dynamic binding. Consider the following [[PHP]] example: <syntaxhighlight lang="php"> class A { public static $word = "hello"; public static function hello() { print self::$word; } } class B extends A { public static $word = "bye"; } B::hello(); </syntaxhighlight> In this example, the PHP interpreter binds the keyword <code>self</code> inside <code>A::hello()</code> to class <code>A</code>, and so the call to <code>B::hello()</code> produces the string "hello". If the semantics of <code>self::$word</code> had been based on late static binding, then the result would have been "bye". Beginning with PHP version 5.3, late static binding is supported.<ref>{{cite web|url=http://us2.php.net/manual/en/language.oop5.late-static-bindings.php|title=Late Static Bindings|access-date=July 3, 2013}}</ref> Specifically, if <code>self::$word</code> in the above were changed to <code>static::$word</code> as shown in the following block, where the keyword <code>static</code> would only be bound at runtime, then the result of the call to <code>B::hello()</code> would be "bye": <syntaxhighlight lang="php"> class A { public static $word = "hello"; public static function hello() { print static::$word; } } class B extends A { public static $word = "bye"; } B::hello(); </syntaxhighlight> ==See also== * {{anl|Branch table}} * {{anl|Higher-order abstract syntax}} ==References== {{reflist}} [[Category:Programming language concepts]] [[Category:Articles with example Java code]] [[Category:Definition]]<!-- scoped in time & context --> [[ja:束縛 (情報工学)]] [[pt:Vinculação de nomes (computação)]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anl
(
edit
)
Template:Citation
(
edit
)
Template:Cite web
(
edit
)
Template:For
(
edit
)
Template:Mono
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)