How we change what others think, feel, believe and do

| Menu | Quick | Books | Share | Search | Settings |

C Style: Standards and Guidelines (contents)

CHAPTER 5 : Naming


CHAPTER 5 : Naming
5.1 Constraints upon naming
5.2 Abbreviations
5.3 Short names
5.4 Separating words
5.5 Spelling of names
5.6 Naming functions
5.7 Indicating functional group
5.8 Naming variables
5.9 Indicating type
5.10 Naming replacement items
5.11 Naming Files and Directories
5.12 Summary

<--Prev page | Next page -->


5.3  Short names

When 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++ )
    EmpNo[i] = 0;


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 */

#define C_DIFF(a, c)  a = 'c' - c  /* may have unexpected results!   */


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.


<--Prev page | Next page -->


Site Menu

| Home | Top | Settings |

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

More Kindle books:

And the big
paperback book

Look inside


Please help and share:


| Home | Top | Menu |

© Changing Works 2002-
Massive Content -- Maximum Speed