Naming convention (programming): Difference between revisions

Content deleted Content added
RegExTypoFix, Replaced: idiosyncracies → idiosyncrasies, using AWB
Line 23:
 
A common recommendation is "Use meaningful identifiers." A single [[word]] may not be as sufficiently meaningful, or specific, as multiple words.
As most [[programming language]]s do not allow the [[whitespace_whitespace (computer science)|whitespace]] in identifiers, a method of delimiting each word is needed (to make it easier for subsequent readers to interpret those character sequences belonging to each word). There are several in widespread use; each with a significant following.
 
One approach is to delimit separate words with a [[alphanumeric|nonalphanumeric]] character. The two characters commonly used for this purpose are the hyphen ('-') and the underscore ('_'), eg, 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 programming language|Lisp]]. Many other languages (eg, languages in the [[C programming language|C]] and [[Pascal programming language|Pascal]] families) reserve the hyphen for use as the [[subtraction]] operator, and so it is not available for use in identifiers.
Line 33:
There is significant disagreement over whether it is permissible to use short (ie, containing few characters) identifiers. The argument being that it is not possible to encode much information, if any, in a short sequence of characters. Whether programmers prefer short identifiers because they are too lazy to type, or think up, longer identifiers, or because in many situations a longer identifier simply clutters the visible code and provides no worthwhile additional benefit (over a shorter identifier) is an open research issue.
 
Often forgotten in the highly personal debates over which naming practice is "best" is the fact that a typical business application will actually be written in several software languages. Every software language has its own idiosyncraciesidiosyncrasies as to special meaning characters (perhaps to indicate local vs global variable), separators, and length.
 
In early software languages, written on punch cards, variable names could be restricted to a maximum 6 characters. It would not be unusual for such cryptically short names (in Fortran) to be migrated to COBOL.
Line 58:
CLASS words (in good practice) 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), 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), serve much the same purpose as [[Hungarian_notationHungarian notation]] prefixes.
 
The purpose of CLASS words, in addition to consistency, is to indicate to the programmer the type of data which provides clues as to what can/should be done to 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.
Line 66:
A 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 dependant 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.
 
==External links==
Line 72:
*[http://www.coding-guidelines.com/cbook/sent787.pdf 100 page pdf] that uses linguistics and psychology to attempt a cost/benefit analysis of identifier naming issues
 
[[categoryCategory:Source code]]
{{compu-lang-stub}}
[[categoryCategory:naming conventions| ]]
 
[[category:Source code]]
[[category:naming conventions| ]]