My naming conventions

General conventions

Capitalization conventions

Names of classes, structs and interfaces


// interfaces
struct ISerialize {};

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

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

Data Members

Naming Enumerations

enum FontStyle

Use "EnumNameNone" when appropriated for the 0 valueNamespaces



Member functions

CString Class::GetName() const;
void Class::SetName(const CString &);


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 nameFor instance, I prefer to declare copy constructors without naming the argumentE.g.

class X
    X(const X&);
    X & operator = (const X&);
    void DrawLine(const Pen &); // is possible to understand, isn't it?
Open(const string &fileName);
Alert(const string &alertText);
Alert(const string &alertMessage);

Some people like to use the prefix "str" for strings. I don't like because choosing the correct name the prefix "str" is redundant.

Open(const string &strFileName);
//is not better than
Open(const string &fileName);

The "Name" suffix for me means text; Otherwise I will specify different like:Open(int fileId);


void Array::GetAt(int index);
void Allocator::Allocate(int numElements);


If choosing the type name to use as the variable name is enough to understand the variable meaning then use it.E.g.

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 wellE.g.

//Don't do this
Paint(const Pen & pen1, const Pen & pen2);
Paint(const Pen & backgroundPen, const Pen & borderPen);

Important variable prefixes

class File
  FILE m_hFile; // or m_FileHandle;
  shared_ptr<Item> m_spItem;
  Item * m_pSelectedItem;