Conventions

一.Conventions for Variable Names

There are a number of generally accepted conventions for naming variables. Following these conventions can improve the readability of a program.

  • An identifier should give some indication of its meaning.
  • Variable names normally are lowercase--index, not Index or INDEX.
  • Like Sales_item, classes we define usually begin with an uppercase letter.
  • Identifiers with multiple words should visually distinguish each word, for example, student_loan(I prefer) or studentLoan, not studentloan. 

Naming conventions are most useful when followed consistently.

The important thing to keep in mind is that other ways to format programs are possible. When you choose a formatting style, think about how it affects readability and comprehension. Once you've chosen a style, use it consistently.(From "C++ Primer(6th)")


二.headers should not include using declarations

Code inside headers ordinarily should not use using declarations. The reason is that the contents of a header are copied into the including program's text. If a header has a using declaration, then every program that includes that header gets that same using declaration. As a result, a program that didn't intend to use the specified library name might encounter unexpected name conflicts.

So, as usual, for code that will go in a header file, we use std:: when we use a library name.

你可能感兴趣的:(Conventions)