syque.com

The Psychology of Quality and More

| Menu | Books | Share | Search | Settings |

C Style: Standards and Guidelines (contents)

CHAPTER 5 : Naming

PART 2 : COMMENTING AND 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.4  Separating words

The name of a symbol may be made up of several words, which should be easily distinguishable to the reader. There are several possible approaches to doing this:

(a) Do not separate the words

This method, used by Kernighan and Ritchie (and others), can result in words which are often difficult to decipher, especially when other words are formed between the constituent words or when abbreviations are used:

 

readdress(), closeventuri(), wdenhcode

 

(b) Use underscores to separate the words

This is the method suggested (but not used!) by Kernighan and Ritchie:

 

read_dress(), close_venturi(), wd_enh_code

 

This has the advantage that words are clearly separated. However, there is a slight penalty of size, as each underscore adds to the length of the name.

(c) Start each word with an uppercase letter

This has the advantage of using less characters than the underscore method. It is also (you might have noticed) the style used in this book.

 

ReadDress(), CloseVenturi(), WdEnhCode

 

Another advantage of this style is that C library function calls are almost invariably all lower-case. Thus it is immediately clear whether a library function or a program function is being called. This style also lends itself well to the prefixing rules (see 5.7, 5.9). The only problem in using it would be where the name became all upper-case, such as with single character variables, making it look like a #define'd constant. In this case the Capitalization rule should be relaxed.

 

There are other variations upon the above styles which may be used, such as using lowercase for the initial letter to differentiate variables from functions.

 

<--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-2015
Massive Content -- Maximum Speed