The Psychology of Quality and More |
CHAPTER 5 : Naming
5.3 Short namesWhen can really short names, like 'i', 'c', etc. be used? They certainly can not be used anywhere, but there are recognized common situations where their usage is not only acceptable, but may also help the readability of the code. Generally speaking, single (two, three..) letter names help where their brevity makes the code more readable, but where their usage is so obvious that a descriptive name is not needed.
Typically, i, j, k are used for array indices:
for ( i = 0; i < MAX_EMP; i++ )
Similarly, c is often used for single characters, s, t for strings, p, q for pointers, x, y, z for coordinates. There are, though, hidden dangers, even amongst the most common names:
EmpNo[1] = EmpNo[i] - 1; /* 1 and i can easily be
confused */ --------------------------------------------------------------------------- This type of hazard can be minimized, whilst retaining the benefit of a short name by using two or three characters, such as ix, ch and ptr instead. Searching for names in an editor is also easier using longer names. For the code to remain readable, the scope of short-name variable usage must be kept strictly limited. The code loses readability when the reader has forgotten the meaning of 'i', and such is the nature of short-term memory that he will start to forget after a few lines or even a page break. There is also a danger when code is likely to 'grow', and an initial simple usage slowly becomes large and complex.
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |