C++ naming convention ::main

Keywords: c++ naming, cpp naming, code style, code formating, coding convention.
Description: My vison of naming convention in C++ programing language.

  1. Introduction
  2. Motivation(s)
  3. Theory and Classification
    1. The name itself
    2. Extra data
    3. Construction of the final name
    4. Examples
    5. Discussion
    6. NOW ME
    7. Note
  4. Documentation.
    1. Complete Rules
    2. Examples
      1. Examples soft
      2. Examples soft extreme
      3. Examples hard
      4. Examples hard extreme
  5. FAQ
  6. Links
  7. Download

  1. Introduction.
      After many years of C++ programming, 
      and studing other styles,
      I am proud to present my C++ naming convention!
      You can call it DEX naming convention :).

  2. Motivation(s)
     Let's suppose we have only one line to observe:
      a->b( &c );
      For start we don't want to know purpose of a.
      This information we can extract from its name.
      The same stands for b.
      What we know:
       1. a is pointer, iterator or class with operator->.
       2. b member of a
     For a we do NOT know:
          1. Member of some class?
          1.1 Static ?
          1.2 Public?
          1.3 Protected?
          1.4 Private?
          1.5 Static protected?
          2. Instance?
          2.1 Global instance?
          2.1.1 Visible only in current module?
          2.1.2. Real global instance?
          2.2. Will be returned?
          3. Functions's parameter?
          3.1 Input?
          3.2 Output
          3.3 Input/Output?
      Similar for b:
          1. Member with operator()?
          1.1 Static member?
          1.2 Public?
          1.3 Protected?
          1.4 Private?
          2. Member function?
          2.1 Static
          2.2 virtual
          2.2.1 virtual const
          2.3 const
          2.4 Public?
          2.5 Protected?
          2.6 Private?
      "Answers" e.g. how a and b could be named.
          1.     M_a .
          1.1    Ms_a.
          1.2    M0_a.
          1.3    M1_a.
          1.4    M2_a.
          1.5    Ms1.
          2.     I_a.
          2.1    E.g. GI_a.
          2.1.1  GIs_a.
          2.1.2. GI_a.
          2.2.   Ir_a.
          3     E.g. Pi_a.
          3.1    Pi_a.
          3.2    Po_a.
          3.3    P_a.
      For b:
          1.    M_b.
          1.1   Ms_b.
          1.2   M0_b.
          1.3   M1_b.
          1.4   M2_b.
          2.    F_b.
          2.1   Fs_b.
          2.2   Fv_b.
          2.2.1 Fvc_.
          2.3   Fs_b.
          2.4   F0_b.
          2.5   F1_b.
          2.6   F2_b.
     Let's study next line.
      GI_a-> F1vc_b( &Pi_c );
      1. Say something about a.
      2. Say something about b.
      3. Say something about c.
      4. Possible place?
      5. Do you see nonsense? 
       1 Pointer, global, have protected virtual const member function with name b.
         Considering its pointer 'qualification' we probably have:
          A *GI_a;
          somewhere GI_a = new B;
          Where B looks like:
          class B: public A
       2. protected, virtual, const, one parameter, possibly declared as C const &Pi_c.
       3. Parameter, input.
       4. Only in: friend function, class classof( *GI_a ), or some derived class type classof( *GI_a ).
       5. Yes: b accept pointer on input parameter.

  3. Theory and Classification
    1. The name itself
      We make the name itself considering the purpose of variable. If the name consist of more the one word they should be separated by uderscore or the firs letters in words should be capital letters. In FAQ you can find comprehensive description of this theme.
    2. Extra data
      Data we add in pure name can be classified in three category.
      Concerning domain:
      global, local, private, protected, private, function/template parameter, namespace member, ...
      Concerning type:
      class, union, typedef, int, char, #define, function, enum, ...
      Concerning qualifications:
      const, static, volatile, virtual, register, return, friend, input, output, base class, inherented class, ...
      This is one of many classificatios which can be made for additional data.
    3. Construction of the final name
      We make this by following next three rules. On pure name we add (1)prefix, (2)postfix or (3) some letters we put in uppercase, depending which information we want to have in final name.
    4. Examples
      Name itself: For define or enums in C/C++ we usualy put the name in capital letters.
      Additionnal information:
      Name prefix or postfix comment Examples
      anarchy <none> <no comment> suspended;
      prefix-domen  m_ class member m_Suspended;
       g_ global g_Suspended;
      prefix-type  p pointer void *pSuspended;
       i integer int iCounter;
      prefix-qualifikator  C class class CObject;
       s static static int sSuspended;
      prefix-domen-type  m_p member pointer void *m_pSuspended;
       g_p global pointer void *g_pSuspended; ( global )
      postfix-type  _type some type value_type
       _compare comparator key_compare
    5. Discussion
      Question: How to make good convention? Ansver: It's very difficult if not impossible. Conditions you have to fullfill are very strict:
      1. It consists of small numer of aditional letters.
      2. They should not disturb reading.
      3. It should be easy to memorize and remeber.
      4. It should give a lot of information.
      Rules 1. and 4. are contradicting. Everything comes to establishing balance betven 1. and 4., and even 3.. Rule 2. looks like it was being temporarly neglected but it has crucial influence in design.

    6. NOW ME!!!
      The solution I offer is very good. If it is the best it is hard to say. Why it is as it is you can read in enclosed FAQ.
    7. NOTE!
      The subject naming is misused. Since on current name we add something or we slightly change it.

  4. Documentation.
    1. Complete Rules
    2. Examples
      1. Examples soft
      2. Examples soft extreme
      3. Examples hard
      4. Examples hard extreme

  5. FAQ

  6. Links