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.5  Spelling of names

The way words are spelled can cause several types of problem.

5.5.1  Sound-alikes

A dangerous practice when naming items is to use spelling (or case) variations, such that when spoken, two names sound the same:


FlangeType, FlangeTipe, FLANGETYPE


Names should always be spelled correctly; there should be no alternative spellings of the same word. You should be able to write the name down from the pronunciation. Kernighan and Plaugher describe the 'telephone test', where it should be possible to read the code over a telephone, and a listener at the other end (who knows the standards used) will be able to write down the code correctly.

This is a problem where there is one name that would be natural to use for several different items. In this case, the name must be 'awarded' to the item which will help most the understanding of the code. Typically, this will be the item with the widest scope (eg. a common structure, rather than one instance of it).

5.5.2  Look-alikes

A similar hazard occurs where two names may be distinctly different, but where the spelling of both words is similar (and even more so when the difference letter is of similar shape). This is something that can happen accidentally, but cause subsequent confusion:


LastWord, LastWard, LostWard, LostWand, LastWind, EastWind


Names which differ by only one letter can even be mistyped into the similar name, especially if the differing letters are adjacent on the keyboard. Similar error can occur where a singular and a plural name both exist, especially where the plural is formed by adding an 's' to the singular. A simple solution is to use names which differ by at least two characters, although this can cause problems where natural names are similar (e.g. describing a person with Height, Weight).

5.5.3  Are-alikes

Another potential source of confusion is to give a local variable the same name as a global variable (or, for that matter, any variable with a wider scope). The global variable is now, of course, obscured and any assignation to it will be redirected to the local variable.

5.5.4  Underscores

Initial and trailing underscores are commonly used by compilers and libraries for special purposes, and it is thus a good idea to avoid strange problems by not starting or ending symbol names with an underscore:




Double underscores should similarly be avoided, for the above reasons, plus the fact that many printers will not show the space between them (thus they appear as one underline):




5.5.5  Numerals

Numerals in names can be confusing, as they can look like letters, and should thus be used with care. Even if they are clear on your terminal, they may not be on someone else's:


AB10S, A8IOS, ABIOS, ABIO5 or A8105 ?


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