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
6
votes
2 answers

How to add namespace prefix to attribute with lxml (node is with other namespace)?

I need to get this xml: Action As I understand…
kepurlaukis
  • 324
  • 5
  • 16
6
votes
3 answers

How flush all keys on one namespace only?

I want know how we can delete all keys for a specific namespace only? FLUSHALL delete all keys, its a problem when using multiple app with same redis server.
Matrix
  • 3,458
  • 6
  • 40
  • 76
6
votes
1 answer

C# Error - Namespaces ManagementClass, ManagementObject, and ManagementObjectCollection could not be found

So, I've got a full list of errors after importing a C# Class. I searched for the error and got a ton of hits however they all say to just add the System.Management namespace which is there and yet it gives these errors. Similar questions. No…
user3851422
  • 63
  • 1
  • 1
  • 3
6
votes
1 answer

How should I reference functions in imported packages?

When creating an R package, there are at least two alternatives for referencing functions in imported packages. Either, Explicitly name the function using the double colon operator whenever you call it, package::function. Add importFrom(package,…
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
6
votes
1 answer

Puppet: stdlib installed but not available in namespace?

as a puppet newbie, I have a problem including the stdlib plugin I would like to use stdlib's file_line, thus I try to include stdlib and call it class service_mon { include stdlib file_line { "${name}_services": path=> ... …
THX
  • 553
  • 2
  • 8
  • 18
6
votes
1 answer

Unqualified name lookup finds inline namespace member

I've written the following code: #include inline namespace M { int j=42; } int main(){ std::cout << j << "\n"; } //j is unqualified name here. //Hence, unqualified name lookup rules will be…
user2953119
6
votes
2 answers

How to limit scope of `using` statement outside of function in C++?

I want to define some static members of template specialization, like this: namespace A { template <> int C::member1_ = 5; template <> int C::member2_ = 5; template <> int…
abyss.7
  • 13,882
  • 11
  • 56
  • 100
6
votes
2 answers

Namespaces and modules in the Swift language

I've been experimenting with Swift on my way home from WWDC. One of the most compelling new features of Swift, in my opinion, was namespacing. I haven't managed to get it to work as I expected it should though. Please see the attached screenshot and…
rhummelmose
  • 647
  • 4
  • 15
6
votes
3 answers

ASMX: What should tempuri.org be replaced with?

Every new web service you create using visual studio comes with a predefined namespace like this: [WebService(Namespace = "http://tempuri.org/")] My web service will run at different clients, and on different domains, so because of this I don't…
JL.
  • 78,954
  • 126
  • 311
  • 459
6
votes
1 answer

Private code generation functions in D?

I'm writing a templated struct in D, which uses string mixins and compile time functions for some of its functionality. Basically, it is in this format: string genCode(T)() { // ... } struct MyTemplate(T) { mixin(genCode!(T)()); //…
exists-forall
  • 4,148
  • 4
  • 22
  • 29
6
votes
2 answers

Namespace & Class name collide

What is the best practice when naming a class same as the end of a namespace? Example: Successful.Domain.Resource { public class Resource {} } Successful.Data.Resource { public class Resources {} } If i want to use the…
user1973285
6
votes
4 answers

C# - Declaration of types within a namespace

what could be a possible use of declaring types within a namespace but not in a class. For ex: namespace Test { public delegate void Ispossible(); } This is valid & does not generate any compilation errors but i can't think of why we would…
SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
6
votes
2 answers

FileNotFoundException Could not locate clojure/java/jdbc__init.class

I have a problem with importing jars in clojure. I used lein to add dependencies. This is code from project.clj (defproject recommendation "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name…
user3549602
  • 69
  • 1
  • 8
6
votes
3 answers

Creating an XML element with a namespace with XmlDocument.CreateElement()

I'm trying to create an XmlDocument using C# and .NET (version 2.0.. yes, version 2.0). I have set the namespace attributes using: document.DocumentElement.SetAttribute( "xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope"); When I…
Frank X
  • 175
  • 1
  • 1
  • 8
6
votes
2 answers

Is there a way to deprecate a namespace?

The short: Is there a way to deprecate a namespace in gcc or clang? The long: Over the years, we have been accumulating all sort of stuff in a catch-all namespace. Now we have decided to put some order into it, and split the namespace into properly…
Diego Sánchez
  • 539
  • 2
  • 12
1 2 3
99
100