Pay attention to the global object are initialized in right order. Because the
order can be arrange in the same translation unit, but not betweentranslation units, see effective c++ Item 47. So we don’t encourage you to
use global object more.
Use _FILE_ and _LINE_ to capture the current file name and line
number.
Use const replace #define to define global constants. Use static const to
define class constant. (const means that it will not change, so I don’t need
keep multi copy in multi objs, so I use static.)
Use Typedef to simplify Complicated Type expressions. It’s very useful in
STL.
Create a zero-valued enumerator to indicate an invalid or default state and
make it the first one.
Declare all member variables private. Then use getter and setterfunctions to access them. Don’t return reference or pointerto private member varaibles through you public memberfunctions.
Don’t use Multithread unless you really need it. Simultaneously respond to
many events, e.g., 1)a web server. 2) interface and working thread. 3) take
advantage of with multiple processor. Just remember, synchronization has
high cost.
Use auto type deduction to make code more readable, and use auto & if you
don’t need to copy the result. Below are highly recommended when yo use
STL container.