Namespace
|
|
It has been suggested that Namespace (computer science) be merged into this article or section. (Discuss) Proposed since December 2009. |
In general, a namespace is a container for a set of identifiers (names), and allows the disambiguation of homonym identifiers residing in different namespaces.[1][2]. Namespaces usually group names based on their functionality.
Contents |
[edit] Naming System
A name in a namespace consists of a namespace identifier and a local name.[3][4] The namespace name is usually applied as a prefix to the local name.
In Augmented_Backus–Naur_Form:
name = <namespace identifier> separator <local name>
[edit] Examples
| Context | Identifier | Namespace identifier | Local name |
|---|---|---|---|
| Path (computing) | /home/user/readme.txt | /home/user (path) | readme.txt (file name) |
| Domain name | www.example.com | example.com (domain) | www (host name) |
| C++ | std::array | std | array |
| UN/LOCODE | US NYC | US (country) | NYC (locality) |
| XML | xmlns:xhtml="http://www.w3.org/1999/xhtml" <xhtml:body> |
http://www.w3.org/1999/xhtml | body |
| Uniform resource name (URN) | urn:nbn:fi-fe19991055 | urn:nbn (National Bibliography Numbers) | fi-fe19991055 |
| Handle System | 10.1000/182 | 10 (Handle naming authority) | 1000/182 (Handle local name) |
| Digital object identifier | 10.1000/182 | 10.1000 (publisher) | 182 (publication) |
[edit] Delegation
Namespaces allow delegation of identifier assignment to multiple name issuing organisation whilst retaining global uniqueness[5]. A central Registration authority registrars the assigned namespace identifiers allocated. Each namespace identifier is allocated to an organisation which is subsequently responsible for the assignment of names in their allocated namespace. This organisation may be a name issuing organisation that assign the names themselves, or another Registration authority which further delegates parts of their namespace to different organisations.
[edit] Hierarchy
A naming scheme that allows subdelegation of namespaces to third parties is a hierarchical namespace
A hierarchy is recursive if the syntax for the namespace identifier are the same for each subdelegation. An example of a recursive hierarchy is the Domain name system.
An example of a non-recursive hierarchy are Uniform resource name representing an ISBN-13 number.
| Registry | Registrar | Example Identifier | Namespace identifier | Namespace |
|---|---|---|---|---|
| Uniform resource name (URN) | Internet Assigned Numbers Authority | urn:isbn:978-3-16-148410-0 | urn | Formal URN namespace |
| Formal URN namespace | Internet Assigned Numbers Authority | urn:isbn:978-3-16-148410-0 | isbn | International Standard Book Numbers as Uniform Resource Names |
| International Article Number (EAN) | GS1 | 978-3-16-148410-0 | 978 | Bookland |
| International Standard Book Number (ISBN) | International ISBN Agency | 3-16-148410-X | 3 | German-speaking countries |
| German publisher code | Agentur für Buchmarktstandards | 3-16-148410-X | 16 | Mohr Siebeck |
[edit] Namespace versus Scope
A namespace identifier may provide context (Scope in computer science) to a name, and the terms are sometimes used interchangeably. However, the context of a name may also be provided by other factors, such as the location where it occurs or the syntax of the name.
| Without a namespace | With a namespace | |
|---|---|---|
| Local scope | Vehicle registration plate | Relative path in a File system |
| Global scope | Universally unique identifier | Domain Name System |
[edit] Namespaces in Programming Languages
For many programming languages, namespace is a context for their identifiers. In an operating system, an example of namespace is a directory. Each name in a directory uniquely identifies one file or subdirectory, but one file may have the same name multiple[6] times.
As a rule, names in a namespace cannot have more than one meaning; that is, different meanings cannot share the same name in the same namespace. A namespace is also called a context, because the same name in different namespaces can have different meanings, each one appropriate for its namespace.
Following are other characteristics of namespaces:
- Names in the namespace can represent objects as well as concepts, be the namespace a natural or ethnic language, a constructed language, the technical terminology of a profession, a dialect, a sociolect, or an artificial language (e.g., a programming language).
- In the Java programming language, identifiers that appear in namespaces have a short (local) name and a unique long "qualified" name for use outside the namespace.
- Some compilers (for languages such as C++) combine namespaces and names in a process called name mangling.
Below is an example of a namespace in C++:
namespace Box1{ int boxSide = 4; } namespace Box2{ int boxSide = 12; } int main () { int boxSide = 42; cout << Box1::boxSide << endl; //output 4 cout << Box2::boxSide << endl; //output 12 cout << boxSide << endl; // output 42 return 0; }
[edit] See also
| Look up namespace in Wiktionary, the free dictionary. |
- 11-Digit Delivery point ZIP code
- Binomial nomenclature (genus-species in biology)
- Chemical nomenclature
- Dewey Decimal Classification
- Digital object identifier
- Domain name system (DNS) names (Internet addresses)
- IP address
- Library of Congress Classification
- Category:National identification numbers
- Star catalogues and astronomical naming conventions
- XML Namespaces
[edit] References
- ^ "C# FAQ: What is a namespace". http://en.csharp-online.net/: C# Online Net. http://en.csharp-online.net/CSharp_FAQ:_What_is_a_namespace. Retrieved 2010-02-23. "A namespace is nothing but a group of assemblies, classes, or types. A namespace acts as a container—like a disk folder—for classes organized into groups usually based on functionality. C# namespace syntax allows namespaces to be nested."
- ^ "namespace". Webopedia. http://www.webopedia.com/TERM/N/namespace.html. Retrieved 2012-03-30. "The set of names in a naming system."
- ^ XML Core Working Group (8 December 2009). "Namespaces in XML 1.0 (Third Edition)". W3C. http://www.w3.org/TR/REC-xml-names/. Retrieved 2012-03-30.
- ^ Moats, Ryan (May 1997). "Syntax". URN Syntax. IETF. p. 1. sec. 2. RFC 2141. https://tools.ietf.org/html/rfc2141#section-2. Retrieved 2012-03-30.
- ^ Sollins & Masinter (December 1994). "Requirements for functional capabilities". Functional Requirements for Uniform Resource Names. IETF. p. 3. sec. 2. RFC 1731. https://tools.ietf.org/html/rfc1731#section-2. Retrieved 2012-03-30.
- ^ "C# FAQ: What is a namespace". http://en.csharp-online.net/: C# Online Net. http://en.csharp-online.net/CSharp_FAQ:_What_is_a_namespace. Retrieved 2010-02-23. "For instance, [under Windows], to access the built-in input-output (I/O) classes and members, use the System.IO namespace. Or, to access Web-related classes and members, use the System.Web namespace."
| This computer programming-related article is a stub. You can help Wikipedia by expanding it. |