From ScorecWiki

Jump to: navigation, search

Named namespaces

  • All classes should be included in a namespace.
  • All namespaces should be included in the SCOREC namespace.
  • Try to extensively define namespaces and avoid using the entire SCOREC namespace.
  • Do not use "using namespace" keywords in header files.
  • Avoid using a using-directive to make all names from a namespace available even in .cc files.
// *Don't* do this!
using namespace foo;
  • You may use a using-declaration anywhere in a .cc file, and in functions, methods or classes in .h files.
// OK in .cc files.
// Must be in a function, method or class in .h files.
using ::foo::bar;
  • Namespace aliases are allowed anywhere in a .cc file, and in functions and methods in .h files.
// OK in .cc files.
// Must be in a function or method in .h files.
namespace fbz = ::foo::bar::baz;

Unnamed namespaces

Use unnamed namespaces when appropriate in .cc files to avoid naming conflicts, but never in .h files.

Global variables

  • Do not use global variable. If unavoidable, define wrapper (interface) function and encapsulate. Limit the right to write global variable so the concurrency shall be guaranteed. Initialize the global variable with constant.
  • Do not declare the same name variable with different scope.
Personal tools