An imaginary space where names uniquely identify things; two things within that space can't have the same name. In computation language, a set of bindings from names to entities. In mathematical language, a function from a set of names to values. As an interesting side note, certain natural languages have noun classifiers which bear an uncanny similarity to namespaces. One such instance is the Vietnamese noun classifier 'đàn', meaning 'chordophone'. The đàn bầu is the monochord; the đàn tranh is the 36-string zither, etc. A number of languages spoken in East and South East Asia are replete with such noun classifiers. -- TheerasakPhotha
Interesting. I don't know Vietnamese, but is this comparable to hat / top hat / fur hat or cycle / bicycle / motorcycle / tandem bicycle? It seems like in English the pattern is either noun-category or adjective* noun-category, that is, the modifiers prefix the categorical noun. Vietnamese seems to use suffixes instead. In English, the modifiers are considered adjectives, though; do tranh or bầu have noun meanings outside of the đàn namespace? -- ScottVokes
People are most familiar with namespaces in filesystems. When programmers use the word namespace, they usually mean what a process sees when executing. Of course, this is a completely artificial distinction. A user is a process and, in a decent OS, vice versa. [Further discussion moved to ShouldUsersBeProcesses.]
Namespaces occur in both operating systems and languages. Let's take a look at the qualities namespaces should possess. Then we'll be able to judge, harshly, the typical implementations of namespaces with their many defects.
Principles of namespaces
A function's point of access to a namespace is where it exists. And since processes can exist anywhere, their local point of view can be from anywhere in the namespace; hence, the distinction between Disconnection and Locality principles. This is strictly superior to existing semantics because Plan 9 and Unix processes can have only one pre-defined point of view, starting at the root node.
Again note, to make sure this point is clear: there is no programming language which gives you a brand new namespace per function. Lisp and Smalltalk are both examples of the complete opposite (eg, inheritance).
Oh, and
-
Plan 9
PlanNine has two categories of namespaces; public, and private. A public namespace is one exported by a filesystem. A private namespace is one internal to a process. Each process composes its private namespace from public namespaces in an arbitrary manner. And there exists no simple mechanism by which a private namespace can be published or shared (duplication is not sharing). Therefore, a Plan 9 OS has the following limitations:
VWST's programmers have implemented namespaces in order to solve a perceived problem with package collision. They also do not understand namespaces; they have no security at all. At least, their implementation does allow one to share bindings. The problem with their implementation is that:
It would be nice if the principles above were motivated somehow. This is how things should be? Ok, but why? Yes, there are zillions of kinds of namespaces that aren't like that, granted, but there's no explanation of why that's bad. For instance, a simple set of names, like Lisp's atom table, is frequently called a name space. What's the harm in calling it that?
At the most abstract level, names are references. So are pointers. So a machine address space can be viewed as a name space. Should it follow the below principles? Why or why not?
Yes! Just because a namespace refers to low-level objects doesn't mean that you're allowed to treat it as anything but a special case of an ideal namespace.
For example, a hard disk driver must represent the address space of blocks it exports as a special case of a general namespace. It must also do this within the semantics of the system, which must be uniform. This is no problem since all it means is that every object in the hard disk driver's namespace (ie, the namespace it implements, not the namespace it runs in - the latter being non-exclusive to it) has create and delete permissions set to OFF. This prevents users from creating or destroying bytes in a disk block (because it is impossible), from creating or destroying blocks (same thing), and from renaming blocks with values outside of the allowed integer interval.
Further, a namespace can't be viewed in isolation because the namespace principles below dictate that you be able to move between namespaces as easily as you do within them. Every functional namespace in the system must be connected to every other namespace (at least transitively), and each link must be bidirectional. So you can't talk about a namespace, but only about individual components of The Namespace.
Uniformity requires you represent everything you expose in the same way, whether it's low-level or abstract. ExoKernel requires you expose low-level objects to sufficiently privileged users. These are fundamental OperatingSystemsDesignPrinciples.
See also OperatingSystemsDesign, ModularProgramming.
CategoryOperatingSystem, CategoryProgrammingLanguage, CategoryNaming, CategoryInfoPackaging