A common feature of naming conventions is to use common prefixes when creating names. The prefix can be used to indicate data type, component name, scope, namespace, copyright holder, or other aspects associated with the identifier.
HungarianNotation and UncleBobsNamingConventions are examples.
Some programming languages use the prefix as a mechanism for determining namespaces, visibility, etc.
Pros
- Those who understand the prefixes can comprehend code faster.
- When things are listed in alphabetical order, things with the same prefix are listed together.
- You can make an educated guess about what another programmer named a thing for which you are searching.
Cons
- Adds noise to names. Often makes code less readable.
- Different programmers often prefer different systems of prefixes, leading to arguments and mismatches.
- If usage of a thing changes, the identifier and all references to it must be updated with a new prefix.
- Many programming languages have better mechanisms for managing namespaces. Use of prefixes as a substitute for such mechanisms is poor style.
On alphabetic ordering
If your tools aren't smart, alphabetic ordering can be a drawback. From the InterfaceHallOfShame:
-
-
-
- One of the features of PowerBuilder is that it allows the user to specify his or her own events, based on operating system messages. These messages are presented to the developer through a list, from which he or she selects the message of interest. The drawback is that there are hundreds of messages, each of which PowerBuilder unnecessarily attaches its own "pbm_" prefix to. Because of this prefix, the user cannot jump through the list by pressing the first character of the desired message, but instead, must physically scroll through the list using the scroll bar. The user ends up wasting a great deal of time searching through the list, when a few keystrokes could have made the process much more efficient.
An IdentifierPrefix is particularly useful when included as an organizing concept for components within a SystemOfNames.
- Or for organizing lists of names or groups of names - for many of TheOtherThings
CategoryNaming CategoryCodingIssues