HOME

My naming conventions

General conventions

Capitalization conventions

Names of classes, structs and interfaces

//derived classes class Dialog {}; class FontDialog : public Dialog{};

// exception classes class SocketException : public std::exception {};


###Data Members

*Use the prefix "m_" for data members and "s_" for static data members.

###Naming Enumerations

* Use the enumeration name as a prefix of the enumerations items
```cpp
enum FontStyle
{
   FontStyleNormal,
   FontStyleBold,
   FontStyleItalic
};

Use "EnumNameNone" when appropriated for the 0 value Namespaces

Functions

Member functions

*Use the prefix "Get" for data member inquiries - Use "Set" to modify values. CString Class::GetName() const; void Class::SetName(const CString &); * For Boolean inquires use: "Is", "Can", "Has" E.g. cpp bool Class::CanSearch() const; bool Class::IsActive() const; bool Class::HasChild() const; Use only affirmative phrases. Don't use IsNotActive, or CannotSearch

Function arguments

In header files is not always necessary to have an argument name For instance, I prefer to declare copy constructors without naming the argument E.g. cpp class X { X(const X&); X & operator = (const X&); void DrawLine(const Pen &); // is possible to understand, isn't it? };

Variables

If choosing the type name to use as the variable name is enough to understand the variable meaning then use it. E.g. ```cpp class Airplane { Propeller m_Propeller; };

Airplane airplane; ```

If the type name is not enough to understand the variable then explain what makes it different Airplane bigAirplane(100); Airplane smallAirplane(1);

Name for containers

If plural name of the item is enough to understand the meaning do like this: E.g. std::vector<Control> m_Controls; if you need to specify a name don't do this std::vector<Control> m_Controls1; Do something like: std::vector<Control> m_StaticControls; std::vector<Control> m_DynamicControls; This tip is valid for arguments and variables as well E.g. //Don't do this Paint(const Pen & pen1, const Pen & pen2); //Do Paint(const Pen & backgroundPen, const Pen & borderPen);

Important variable prefixes