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
Namespace
(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!
===Emulating namespaces=== In programming languages lacking language support for namespaces, namespaces can be emulated to some extent by using an [[identifier naming convention]]. For example, [[C (programming language)|C]] libraries such as [[libpng]] often use a fixed prefix for all functions and variables that are part of their exposed interface. Libpng exposes identifiers such as: png_create_write_struct png_get_signature png_read_row png_set_invalid This [[naming conventions (programming)|naming convention]] provides reasonable assurance that the [[identifier]]s are unique and can therefore be used in larger programs without [[naming collision]]s.<ref>{{Cite web|url=http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=286 |title=Why I Hate Namespaces |author=Danny Kalev |url-status=bot: unknown |archive-url=https://web.archive.org/web/20160709115609/http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=286 |archive-date=2016-07-09 }}</ref> Likewise, many packages originally written in [[Fortran]] (e.g., [[BLAS]], [[LAPACK]]) reserve the first few letters of a function's name to indicate the group to which the function belongs. This technique has several drawbacks: * It doesn't scale well to nested namespaces; identifiers become excessively long since all uses of the identifiers must be [[fully qualified name|fully namespace-qualified]]; * Individuals or organizations may use inconsistent naming conventions, potentially introducing unwanted obfuscation; * Compound or "query-based" operations on groups of identifiers, based on the namespaces in which they are declared, are rendered unwieldy or unfeasible; * In languages with restricted identifier length, the use of prefixes limits the number of characters that can be used to identify what the function does; this is a particular problem for packages originally written in [[Fortran|FORTRAN 77]], which offered only 6 characters per identifier; for example, the name of the [[BLAS]] function <code>DGEMM</code> indicates that it operates on double-precision floating-point numbers (<code>D</code>) and general matrices (<code>GE</code>), with only the last two characters (<code>MM</code>) showing what it actually does: matrix–matrix multiplication. It also has a few advantages: * No special software tools are required to locate names in source-code files; a simple program like [[grep]] suffices; * There are no namespace-related name conflicts; * There is no need for name mangling, and thus no potential incompatibility problems.
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)