|
A namespace is a context in which a group of one or more identifiers might exist. An identifier defined in a namespace is associated with that namespace. The same identifier can be independently defined in multiple namespaces, that is, the meaning associated with an identifier defined in one namespace is independent of the same identifier declared in any other namespace. Languages that support namespaces specify the rules that determine which namespace an occurrence of an identifier (ie, not its definition) belongs to. Identifiers (IDs) are lexical tokens that name entities. ...
For example, Bill works for company X and his employee ID is 123. John works for company Y and his employee ID is also 123. The reason Bill and John can be identified by the same ID number is because they work for different companies. The different companies in this case would symbolize different namespaces. There would be serious confusion if the two men worked for the same company, and still had the same employee ID. For instance, when it comes time to pay them who gets the pay packet? In large computer programs or documents it is not uncommon to have hundreds or thousands of identifiers. Namespaces (or a similar technique, see Emulating namespaces) provide a mechanism for hiding local identifiers. They provide a means of grouping logically related identifiers into corresponding namespaces, thereby making the system more modular. A computer program is a collection of instructions that describe a task, or set of tasks, to be carried out by a computer. ...
A document contains information. ...
A namespace is a context in which a group of one or more identifiers might exist. ...
Modularity is a concept that has applications in the contexts of computer science, particularly programming, as well as cognitive science in investigating the structure of mind. ...
Many modern computer languages provide support for namespaces. In some programming languages (eg. C++, Python), these identifiers naming namespaces are themselves associated with an enclosing namespace. Thus, in these languages namespaces can nest, forming a namespace tree. At the root of this tree is the unnamed global namespace. The term computer language is a more expansive and alternate term for the more commonly-used term programming language. ...
C++ (pronounced see plus plus, IPA: ) is a general-purpose, high-level programming language with low-level facilities. ...
Python is a programming language created by Guido van Rossum in 1990. ...
In computer science, a tree is a widely-used computer data structure that emulates a tree structure with a set of linked nodes. ...
Use in common languages
In C++, a namespace is defined with a namespace block. C++ (pronounced see plus plus, IPA: ) is a general-purpose, high-level programming language with low-level facilities. ...
namespace foo { int bar; } Within this block, identifiers can be used exactly as they are declared. Outside of this block, the namespace specifier must be prefixed. For example, outside of namespace foo, bar must be written foo::bar. C++ includes another construct that makes this verbosity unnecessary. By adding the line using namespace foo; to a piece of code, the prefix foo:: is no longer needed. Code that is not explicitly declared within a namespace is considered to be in the global namespace. Namespace resolution in C++ is hierarchical. This means that within the hypothetical namespace food::soup, the identifier chicken refers to food::soup::chicken if it exists. If it doesn't exist, it then refers to food::chicken if it exists. If neither exist, chicken refers to an identifier in the global namespace. Namespaces in C++ are most often used to avoid naming collisions. Although namespaces are used extensively in recent C++ code, most older code does not use this facility. For example, the entire C++ standard library is defined within namespace std, but before standardization many components were originally in the global namespace. In C++, the Standard Library is a collection of classes and functions, which are written in the core language. ...
In the Java programming language, the idea of a namespace is embodied in Java packages. All code belongs to a package, although that package need not be explicitly named. Code from other packages is accessed by prefixing the package name before the appropriate identifier, for example class String in package java.lang can be referred to as java.lang.String (this is known as the fully qualified class name). Like C++, Java offers a construct that makes it unnecessary to type the package name (import). However, certain features (such as reflection) require the programmer to use the fully qualified name. Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s. ...
A Java package is a Java programming language mechanism for organizing classes into namespaces. ...
java. ...
A fully qualified domain name (or FQDN) is an unambiguous domain name that specifies the nodes position in the DNS tree hierarchy absolutely. ...
In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior. ...
Unlike C++, namespaces in Java are not hierarchical as far as the syntax of the language is concerned. However, packages are named in a hierarchical manner. For example, all packages beginning with java are a part of the Java platform—the package java.lang contains classes core to the language, and java.lang.reflect contains core classes specifically relating to reflection. The Java platform is the name for a computing environment, or platform, from Sun Microsystems which can run applications developed using the Java programming language and set of development tools. ...
In Java (as well as Ada, C#, and others), namespaces/packages express semantic categories of code. For example, in C#, namespace System contains code provided by the system (the .NET framework). How specific these categories are and how deep the hierarchies go differ from language to language. Ada is a structured, statically typed imperative computer programming language designed by a team led by Jean Ichbiah of CII Honeywell Bull during 1977â1983. ...
C# (pronounced see-sharp) is an object-oriented programming language developed by Microsoft as part of their . ...
Microsoft . ...
Function and class scopes can be viewed as implicit namespaces that are inextricably linked with visibility, accessibility, and object lifetime. In computer science, a subroutine (function, procedure, or subprogram) is a sequence of code which performs a specific task, as part of a larger program, and is grouped as one, or more, statement blocks; such code is sometimes collected into software libraries. ...
In object-oriented programming, classes are used to group related variables and functions. ...
In computer programming in general, a scope is an enclosing context. ...
In computer science, the object lifetime (or life cycle) of an object in object-oriented programming is the time between an objects creation (also known as instantiation or construction) till the object is no longer used, and is destructed or freed. ...
XML Namespaces -
Although it is not a programming language, XML makes extensive use of namespaces. Many modern computer languages provide support for namespaces. ...
The Extensible Markup Language (XML) is a W3C-recommended general-purpose markup language that supports a wide variety of applications. ...
Emulating namespaces In programming languages that do not provide language support for namespaces, namespaces can be emulated to some extent by using an identifier naming convention. For example, C libraries such as Libpng often use a fixed prefix for all functions and variables that are part of their exposed interface. Libpng exposes identifiers such as: In computer programming a naming convention is a set of rules for choosing identifiers. ...
C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
libpng is the official PNG reference library (originally called pnglib). ...
libpng is the official PNG reference library (originally called pnglib). ...
png_create_write_struct png_get_signature png_read_row png_set_invalid This gives reasonable assurance that the identifiers are unique and can therefore be used in larger programs without fear of identifier collisions. Identifiers (IDs) are lexical tokens that name entities. ...
Unfortunately, this technique has several drawbacks: - It doesn't scale well to nested namespaces; identifiers become excessively long.
- Individuals or organizations may use dramatically inconsistent naming conventions, potentially introducing unwanted obfuscation.
- Compound or 'query-based' operations on groups of identifiers, based on the namespaces in which they are declared, is rendered unwieldy or unfeasible.
- All uses of the identifiers must, in effect, be fully namespace-qualified. Languages with direct support for namespaces usually provide ways for the programmer to declare up front that they wish to use some or all identifiers from a specific namespace, which they can then use without qualification for the remainder of the block.
A fully qualified domain name (or FQDN) is an unambiguous domain name that specifies the nodes position in the DNS tree hierarchy absolutely. ...
See also |