Science Fair Projects Ideas - Namespace (programming)

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Namespace (programming)

In many programming languages, a namespace is a context for identifiers. Some modern programming languages such as C++ or Java can handle multiple namespaces within the language.

History

In early programming languages, such as C, namespaces were defined implicitly by the semantics of a program. For example, an identifier defined within a function only has meaning within the context of that function. These implicitly defined namespaces were inextricably linked with the ideas of visibility, accessibility, and lifetime (see scope).

As programming progressed and software projects became more complex, a need was seen for a language construct which separated visibility from context. Before namespaces, naming collisions were avoided by prefixing characters to an identifier in various nonstandard ways. This practice encumbered readability. Therefore, namespaces have been added to most modern languages.

Use in common languages

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 declared within a namespace is considered to be in the default namespace.

Namespaces in C++ are hierarchical. Within the hypothetical namespace food::fruit, the identifier orange refers to food::fruit::orange if it exists, or if not food::orange if it exists. If neither exist, orange refers to an identifier in the default namespace.

Namespaces in C++ are most often used to avoid naming collisions. Although namespaces are used extensively in recent C++ code, most older code does not use this facility. For example, the entire standard library is defined within namespace std, and in earlier standards of the language, in the default namespace.

In Java, the idea of a namespace is embodied in packages. All code belongs to a package, although that package need not be explicitly named. Code from other packages is accessed by prefixing the package name before the appropriate identifier, for example class String in package java.lang can be referred to as java.lang.String (this is known as the fully qualified class name). Like C++, Java offers a construct which makes it unnecessary to type the package name (import). However, certain features (such as reflection) require the programmer to use the fully qualified name.

Unlike C++, namespaces in Java are not hierarchical as far as the syntax of the language is concerned. However, packages are named in a hierarchical manner. For example, all packages beginning with java are a part of the Java platform, the package java.lang contains classes core to the language, and java.lang.reflect contains core classes specifically relating to reflection.

In Java (as well as Ada, C#, and others), namespaces/packages express semantic categories of code. For example, in C#, namespace System contains code provided by the system (the .NET framework). How specific these categories are and how deep the hierarchies go differ from language to language.

Although it is not a programming language, XML makes extensive use of namespaces.

See also

10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice