3.3 Naming Style

I l @ ve RuBoard

Names can contain both uppercase and lowercase letters . In this book we use all lowercase names for variables (e.g., source_ptr , current_index ). All uppercase is reserved for constants (e.g., MAX_ITEMS , SCREEN_WIDTH ). This convention is the classic convention followed by most C and C++ programs.

Many newer programs use mixed-case names (e.g., RecordsInFile ). Sometimes they use the capitalization of the first letter to indicate information about the variable. For example, recordsInFile might be used to denote a local variable while RecordsInFile would denote a global variable. (See Chapter 9 for information about local and global variables.) You should be careful when making up rules for your variables because the more complex the rules, the more likely someone will violate them or get confused .

One additional note on variable names: please use whole words. The problem with abbreviations is that there are too many different ways of abbreviating the same word. This is especially true when programmers think that to abbreviate a word, you write down the word and then cross out random letters. I've seen "Ground Point" named gp , ground_pt , gnd_pt , g_pnt , and many others. On the other hand, there's only one full spelling: ground_point .

Also, I work for a company which has people from 62 different countries working together to produce code. The non-English speakers have real difficulty looking up the more unusual abbreviations. Words in the dictionary make things much easier to understand for people who have to deal with the twin complexities of English and C++.

Which naming convention you use is up to you. It is more a matter of religion than of style. However, using a consistent naming style is extremely important. In this book we have chosen the first style ”lowercase variable names and uppercase constants ”and we use it throughout the book. (Note that this convention is growing less common as old-style #define constants are being replaced with new-style const ones.)

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net