Many modern computer languages provide support for namespaces.
A namespace is a context for identifiers. An identifier defined in a namespace is associated with that namespace. An identifier can be defined in multiple namespaces. The meaning of an identifier in one namespace is completely separate from the meaning it has in any other namespace. Thus, a namespace introduces a new domain in which one can define any identifier with the guarantee that it will not clash with existing id ...
An XML namespace is a W3C standard for providing uniquely named elements and attributes in an XML instance. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabulary is given a namespace then the ambiguity between identically named elements or attributes can be resolved.
All element names within a namespace must be unique.
A simple example would be to consider an XML instance that contained references to a customer and an ordered product. Both the customer element and th ...
In C++, a namespace is defined with a namespace block.
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 which 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 dec ...
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:
png_create_write_struct
png_get_signature
png_read_row
png_set_invalid
This gives reasonable assurance that the identifiers are unique and can therefor ...