Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Scope (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Qualified names == As we have seen, one of the key reasons for scope is that it helps prevent name collisions, by allowing identical names to refer to distinct things, with the restriction that the names must have separate scopes. Sometimes this restriction is inconvenient; when many different things need to be accessible throughout a program, they generally all need names with global scope, so different techniques are required to avoid name collisions. To address this, many languages offer mechanisms for organizing global names. The details of these mechanisms, and the terms used, depend on the language; but the general idea is that a group of names can itself be given a name β a prefix β and, when necessary, an entity can be referred to by a ''qualified name'' consisting of the name plus the prefix. Normally such names will have, in a sense, two sets of scopes: a scope (usually the global scope) in which the qualified name is visible, and one or more narrower scopes in which the ''unqualified name'' (without the prefix) is visible as well. And normally these groups can themselves be organized into groups; that is, they can be ''nested''. Although many languages support this concept, the details vary greatly. Some languages have mechanisms, such as ''namespaces'' in [[C++]] and [[C Sharp (programming language)|C#]], that serve almost exclusively to enable global names to be organized into groups. Other languages have mechanisms, such as ''packages'' in [[Ada (programming language)|Ada]] and ''structures'' in [[Standard ML]], that combine this with the additional purpose of allowing some names to be visible only to other members of their group. And object-oriented languages often allow classes or singleton objects to fulfill this purpose (whether or not they ''also'' have a mechanism for which this is the primary purpose). Furthermore, languages often meld these approaches; for example, [[Perl]]'s packages are largely similar to C++'s namespaces, but optionally double as classes for object-oriented programming; and [[Java (programming language)|Java]] organizes its variables and functions into classes, but then organizes those classes into Ada-like packages.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)