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 libraries e.g. 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_invalidThis provides reasonable assurance that the identifiers are unique and can therefore be used in larger programs without fear of identifier naming collisions. Likewise, many packages originally written in Fortran (e.g., BLAS, LAPACK) reserve the first few letters of a function's name to indicate which group it belongs to.
Unfortunately, this technique has several drawbacks:
- It doesn't scale well to nested namespaces; identifiers become excessively long.
- Individuals or organizations may use dramatically 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, is rendered unwieldy or unfeasible.
- All uses of the identifiers must, in effect, be fully namespace-qualified. Languages with direct support for namespaces usually provide ways for the programmer to declare up front that they wish to use some or all identifiers from a specific namespace, which they can then use without qualification for the remainder of the block.
- In languages in which identifier length is restricted, 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 77 that offered only 6 characters per identifier. For example, the BLAS function
DGEMM
function indicates that it operates on double precision numbers (the 'D'), general matrices (the 'GE') and only the last two characters show what it actually does: a matrix-matrix multiplication (the 'MM').
Read more about this topic: Namespace (computer Science)
Famous quotes containing the word emulating:
“Here come real stars to fill the upper skies,
And here on earth come emulating flies....”
—Robert Frost (18741963)