Skip to content

Classes and Structs

Chuck Atkins edited this page May 5, 2017 · 7 revisions
  1. Class naming: use PascalCase, also known as UpperCamelCase, for class naming: ADIOS, Transform, Transport.

    • Don't
      class filedescriptor :  public transport
      { ...
      or
      class file_descriptor :  public transport
      { ...
    • Do
      class FileDescriptor :  public Transport
      { ...
  2. Class members naming: Continue to use PascalCase for all class members, function and data, however adding an additional m_ prefix to denote data members: m_XMLConfig, m_Shape, etc. This method enables easy autocomplete of members in many editors as it's encouraged by the clang-format.

    • Don't
      class Transport
      { 
      public: 
         std::string Name;
    • Do
      class Transport
      { 
      public: 
          std::string m_Name;
  3. Structs: reserve structs for public member variables only, structs should not have member functions, derived classes (inheritance), or private members. Structs will using the the same naming convention as Classes, without the m_ prefix on data members.

    • Don't
      struct Attribute
      { 
      public: 
          std::string  m_Name;
          std::string  m_Type;
          std::string  m_Value;
          // Use a class instead
          void SetName( const std::string name );
      };
    • Do
      struct Attribute
      { 
          std::string Name;
          std::string Type;
          std::string Value;
      };
  4. Single header (.h) and source (.cpp) file per class: Example: class Transport must have Transport.h and Transport.cpp only; do not define several classes in the same file. Define structs in single header file, ( e.g. Attribute in Attribute.h ). Exceptions:

    • Templates
    • Nested structs (only used a few times)
    • enum class