The Psychology of Quality and More |
CHAPTER 5 : Naming
5.4 Separating wordsThe 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 wordsThis 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 wordsThis 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 letterThis 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.
|
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 |