Potential benefitsSome of the potential benefits that can be obtained by adopting a naming convention include the following:
ChallengesThe choice of naming conventions (and the extent to which they are enforced) is often a contentious issue, with partisans holding their viewpoint to be the best and others to be inferior. Moreover, even with known and well-defined naming conventions in place, some organizations may fail to consistently adhere to them, causing inconsistency and confusion. These challenges may be exacerbated if the naming convention rules are internally inconsistent, arbitrary, difficult to remember, or otherwise perceived as more burdensome than beneficial. Business value of naming conventionsAlthough largely hidden from the view of most business users, well-chosen identifiers make it significantly easier for subsequent generations of analysts and developers to understand what the system is doing and how to fix or extend the source code for new business needs. For example, although the following: a = b * c is syntactically correct, it is entirely opaque as to intent or meaning. Contrast this with: weekly_pay = hours_worked * pay_rate which implies the intent and meaning of the source code, at least to those familiar with the underlying context of the application. Common elementsThe exact rules of a naming convention depend on the context in which they are employed. Nevertheless, there are several common elements that influence most if not all naming conventions in common use today. Length of identifiersA fundamental element of all naming conventions are the rules related to identifier length (i.e., the finite number of individual characters allowed in an identifier). Some rules dictate a fixed numerical bound, while others specify less precise heuristics or guidelines. Identifier length rules are routinely contested in practice, and subject to much debate academically. Some considerations:
It is an open research issue whether programmers prefer shorter identifiers because they are easier to type, or think up, than longer identifiers, or because in many situations a longer identifier simply clutters the visible code and provides no perceived additional benefit. Brevity in programming could be in part attributed to early linkers which required variable names to be restricted to 6 characters in order to save memory. Letter case and numeralsSome naming conventions limit whether letters may appear in uppercase or lowercase. Other conventions do not restrict letter case, but attach a well-defined interpretation based on letter case. Some naming conventions specify whether alphabetic, numeric, or alphanumeric characters may be used, and if so, in what sequence. Multiple-word identifiersA common recommendation is "Use meaningful identifiers." A single word may not be as meaningful, or specific, as multiple words. Consequently, some naming conventions specify rules for the treatment of "compound" identifiers containing more than one word. Word boundariesAs most programming languages do not allow whitespace in identifiers, a method of delimiting each word is needed (to make it easier for subsequent readers to interpret which characters belong to which word).
One approach is to delimit separate words with a nonalphanumeric character. The two characters commonly used for this purpose are the hyphen ('-') and the underscore ('_'), (e.g., the two-word name two words would be represented as two-words or two_words). The hyphen is used by nearly all programmers writing Cobol and Lisp; it is also common for selector names in Cascading Style Sheets. Many other languages (e.g., languages in the C and Pascal families) reserve the hyphen for use as the subtraction infix operator, and so it is not available for use in identifiers.
Another approach is to indicate word boundaries using capitalization, thus rendering two words as either twoWords or TwoWords. The term CamelCase (or camelCase) is sometimes used to describe this technique. CamelCase, however, can spoil readability when acronym and initialism must be used as words. Moreover it may cause difficulty when the source code is inspected with a common spell checker such as "aspell" etc. Metadata and hybrid conventionsSome naming conventions represent rules or requirements that go beyond the requirements of a specific project or problem domain, and instead reflect a greater over-arching set of principles defined by the software architecture, underlying programming language or other kind of cross-project methodology. Hungarian notation
Positional NotationA style used for very short (8 characters and less) could be: LCCIIL01, where LC would be the application (Letters of Credit), C for COBOL, IIL for the particular process subset, and the 01 a sequence number. This sort of convention is still in active use in mainframes dependent upon JCL and is also seen in the 8.3 (maximum 8 characters with period separator followed by 3 character file type) MS-DOS style. Composite word scheme (OF Language)One of the earliest published convention systems was IBM's "OF Language" documented in a 1980s IMS (Information Management System) manualcitation needed. It detailed the PRIME-MODIFIER-CLASS word scheme, which consisted of names like "CUST-ACT-NO" to indicate "customer account number". PRIME words were meant to indicate major "entities" of interest to a system. MODIFIER words were used for additional refinement, qualification and readability. CLASS words ideally would be a very short list of data types relevant to a particular application. Common CLASS words might be: NO (number), ID (identifier), TXT (text), AMT (amount), QTY (quantity), FL (flag), CD (code), W (work) and so forth. In practice, the available CLASS words would be a list of less than two dozen terms. CLASS words, typically positioned on the right (suffix), served much the same purpose as Hungarian notation prefixes. The purpose of CLASS words, in addition to consistency, was to specify to the programmer the data type of a particular data field. Prior to the acceptance of BOOLEAN (two values only) fields, FL (flag) would indicate a field with only two possible values. Language-specific conventionsC and C++ languages
Java language
Visual Basic, VB.NET and BASIC languages
Perl
See alsoReferences
External links
| |