Name binding

In computer programming, name binding is the association of a data or code entity with an identifier.[1] An identifier bound to an entity is said to reference that entity. A machine language has no built-in notion of identifiers, but name-entity binding as a service and notation for the programmer is implemented by higher-level programming languages. Binding is intimately connected with scoping, as scope determines which names bind to which entities – at which locations in the program code (lexically) and in which one of the possible execution paths (temporally).

Use of an identifier id in a context that establishes a binding for id is called a binding (or defining) occurrence. In all other occurrences (e.g., in expressions, assignments, and subprogram calls), an identifier stands for what it is bound to; such occurrences are called applied occurrences.

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 entity in memory, possibly referenced by a variable or bound to an identifier.

Consider the following Java code:

import java.util.LinkedList;

LinkedList<String> list; // implicitly initialised to 'null'
list = new LinkedList<>();
list.add("foo");
list = null;
{ 
    LinkedList<Integer> list = new LinkedList<>(); 
    list.add(2);
}

The identifier list is bound to a variable in the first line; in the second, 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 null. 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 list.

See also

References

  1. ^ Microsoft (May 11, 2007), Using early binding and late binding in Automation, Microsoft, retrieved May 11, 2009

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.