Questions tagged [namespaces]

A namespace is a container that provides context for identifiers, within which names are unique.

A namespace is a container that provides context for identifiers, within which names are unique. In many implementations, identifiers can be disambiguated between namespaces by prepending the identifier with the namespace, separated by a delimiter such as a period (.) in and , double-colon (::) in or backslash (\) in .

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 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 for internal use in the compiler in a process called name mangling.

PHP

Namespaces were introduced into PHP from version 5.3 onwards. In PHP, a namespace is defined with a namespace block.

namespace phpstar {
    class fooBar {
        public function foo() {
            echo 'hello world, from function foo';
        }

        public function bar() {
            echo 'hello world, from function bar';
        }
    }
}

XML

In XML, the XML namespace specification enables the names of elements and attributes in an XML document to be unique. Using XML namespaces, XML documents may contain element or attribute names from more than one XML vocabulary.

Python

In Python, namespaces are defined by the individual modules, and since modules can be contained in hierarchical packages, then name spaces are hierarchical as well. In general when a module is imported then the names defined in the module are defined via that module's name space, and are accessed in from the calling modules by using the fully qualified name.

.NET

All .NET Framework classes are organized in namespaces. When referencing a class, one should specify either its fully qualified name, which means namespace followed by the class name,

C++

In C++, a namespace is defined with a namespace block.

namespace abc {
    int bar;
}
12341 questions
7
votes
2 answers

Create a class at run time within a module/namespace

Creating a class at runtime is done as follows: klass = Class.new superclass, &block Object.const_set class_name, klass Example: class Person def name "Jon" end end klass = Class.new Person do def name "#{super} Doe" …
danlee
  • 733
  • 8
  • 13
7
votes
4 answers

Does the anonymous namespace enclose all namespaces?

In C++ you specify internal linkage by wrapping your class and function definitions inside an anonymous namespace. You can also explicitly instantiate templates, but to be standards conforming any explicit instantiations of the templates must occur…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
7
votes
4 answers

What does global:: mean in the .Net designer files?

Here is a question that I have had for some time but never actually got around to asking... In quite a lot of the designer files that Visual Studio generates some of the variables are prefixed with global:: Can someone explain what this means, what…
Calanus
  • 25,619
  • 25
  • 85
  • 120
7
votes
3 answers

Where Does Visual Studio Remember Which Folders are "Namespace Providers"?

OK, this may be really simple, but it is Friday and it has been a long week. I can't seem to find an answer for the life of me. Basically, I have a project in which the Namespace Provider property has been set. When a colleague gets the up to date…
Rob Cooper
  • 28,567
  • 26
  • 103
  • 142
7
votes
2 answers

Is there a PHP namespace shortcut for this?

I'm trying to find a way to mass apply these namespaces, as this would be inconvenient to write out. I know I can simply do, use jream\ as j but I would like to see if it's possible to avoid the backslash. require '../jream/Autoload.php'; use…
JREAM
  • 5,741
  • 11
  • 46
  • 84
7
votes
2 answers

Using Devise with multiple namespaces for the same Model

I want to use Devise with two namespaces: an API namespace, and the default namespace, but the two seem to be conflicting when a user tries to sign in. Meaning, whichever namespace that references Devise first ends up being the final redirection…
beeudoublez
  • 1,222
  • 1
  • 12
  • 27
7
votes
1 answer

working with package without Namespace in R

I have got betaversion from website. The only available is windows installation as mybetapackage.zip file. When I installed the package, it does not work when I load it. > utils:::menuInstallLocal() > require(mypackage) Loading required package:…
jon
  • 11,186
  • 19
  • 80
  • 132
6
votes
2 answers

Unnamed namespace access rules

I was looking over section 7.3.1.1 in the C++03 standard expecting to find some description of the access rules for items defined in an unnamed namespace. The rules seem to be a little different for unnamed namespaces, since you cannot fully qualify…
void.pointer
  • 24,859
  • 31
  • 132
  • 243
6
votes
3 answers

c++ and injected base name

The following code does not compile in gcc: namespace One{ class A{ }; }; namespace Two{ class A{ public: void what(){ cout << "Two::A says what!" << endl; } }; class B : public One::A{ …
kamziro
  • 7,882
  • 9
  • 55
  • 78
6
votes
2 answers

R: temporarily overriding functions and scope/namespace

Consider the following R code: local({ lm <- function(x) x^2 lm(10) }) This temporarily overrides the lm function, but once local has been executed it will "be back to normal". I am wondering why the same approach does not seem to work in this…
Stefan
  • 1,835
  • 13
  • 20
6
votes
3 answers

How to Import Other Namespaces into Visual C#?

Sorry if my question seems a little noobish but I can't find an answer. I would like to use DirectInput for my XNA game. I've read around and it seems this is the best way to get input from a gamepad other than a XBox 360 controller. The first step…
MrSplosion
  • 183
  • 1
  • 3
  • 10
6
votes
2 answers

how to add xml namespaces

This feed (snippit of it) needs to look exactly like this: what do I add to this C# code to add that extra…
Scott Kramer
  • 1,711
  • 3
  • 24
  • 37
6
votes
2 answers

adding controllers with a namespace admin as a subfolder

i have a simple cms on ROR 3.2. with this folder scheme: app |controllers |my controllers but i wanted to have an "admin" section where i could have some controllers too. so i created rails generate controller admin/Users app | controllers |admin…
Miguel J.
  • 63
  • 1
  • 4
6
votes
2 answers

XSD with imports and namespaces

Hi I am trying to get my mind around XSDs, XML and namespaces but I can't get things to work the way I want them to. I have an XSD which, at the moment, starts like this:
cbp
  • 25,252
  • 29
  • 125
  • 205
6
votes
1 answer

Understanding namespace documentation

I am struggling to understand how doxygen works with namespaces in Python. A namespace of the name "filename" i.e. temp.py, is generated by default. I can also declare new namespaces with the \package or \namespace command. However, what I don't…
Ani
  • 918
  • 1
  • 10
  • 25