Other Coding Rules: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Namespaces == We prefer fully qualified names (e.g. std::cout). Using directives (e.g. using namesapce std) are not welcome. Using directives in headers will result in the c...") |
m (typo) |
||
Line 3: | Line 3: | ||
We prefer fully qualified names (e.g. std::cout). | We prefer fully qualified names (e.g. std::cout). | ||
Using directives (e.g. using | Using directives (e.g. "using namespace std") are not welcome. Using directives in headers will result in the code being rejected. | ||
Using declarations (e.g. using std::cout) are tolerated, but should be used only in the innermost possible scope (i.e. usually function scope). Fully qualified names are still preferred. | Using declarations (e.g. "using std::cout") are tolerated, but should be used only in the innermost possible scope (i.e. usually function scope). Fully qualified names are still preferred. | ||
== Other Pieces of Advice == | == Other Pieces of Advice == | ||
* Prefer C++ means over C means. | |||
* Prefer STL-container over raw arrays and new[]/delete[]. | |||
* Use new/delete only when necessary. Prefer automatic storage duration. | |||
* Throw exceptions instead of retuning error codes. | |||
* When returning a pointer, don't return a 0-pointer in case of an error (returning a 0-pointer is still valid, if it does not represent an error situation). | |||
* Don't use C++0x features (until we made sure everyone's compiler supports these) | |||
* Remember the Rule of Three. |
Revision as of 20:27, 4 October 2011
Namespaces
We prefer fully qualified names (e.g. std::cout).
Using directives (e.g. "using namespace std") are not welcome. Using directives in headers will result in the code being rejected.
Using declarations (e.g. "using std::cout") are tolerated, but should be used only in the innermost possible scope (i.e. usually function scope). Fully qualified names are still preferred.
Other Pieces of Advice
- Prefer C++ means over C means.
- Prefer STL-container over raw arrays and new[]/delete[].
- Use new/delete only when necessary. Prefer automatic storage duration.
- Throw exceptions instead of retuning error codes.
- When returning a pointer, don't return a 0-pointer in case of an error (returning a 0-pointer is still valid, if it does not represent an error situation).
- Don't use C++0x features (until we made sure everyone's compiler supports these)
- Remember the Rule of Three.