Take the 2-minute tour ×

I would like to know what are the most used naming conventions in C++ for the following cases :

1) Classes that have abbreviations : MyCRTPClass or MyCrtpClass ?

2) Template parameters : template<class TYPE> or template<class Type>. If it is the second case, is there a naming convention that allow "immediate" differentiation between a class name and a template parameter ?

3) If I want to make a typedef of my template parameter TYPE (or Type) is there any widespread convention ? And moreover what is the most used style of a typedef ?

4) For local variables what is the most used : my_local_variable or myLocalVariable ?

5) For data members : _myDataMember vs myDataMember_ vs myDataMember vs mMyDataMember vs m_myDataMember ? (currently I use the first one)

6) Any widespread convention for static const data members ?

I for some of these questions, there is no "common" naming convention, I would be great to tell me what is surely againt all the conventions...

Thank you very much !

share|improve this question

closed as not constructive by this.lau_, Vlad Lazarenko, ta.speot.is, chris, David Rodríguez - dribeas Aug 2 '12 at 3:43


None of this matters too much as long as you're consistent. It's very subjective. You'll have to watch you don't follow the underscore with a capital letter on #5, though. –  chris Aug 2 '12 at 3:39

2 Answers 2

up vote 0 down vote accepted

CRTP is an acronym and should always be capitalized.

Do not spell any identifier in all capitals, those are conventionally reserved for macros.

Typedef of template parameter? No convention there, it's too rare a need.

Local variables: Irrelevant, it's usually matched to the project's coding guidelines. my_local_variable is the convention used by the C++ Standard library, so tends to be favoured for projects started from scratch.

For data members, there is no widespread convention, nor for static const data members. If you're writing a class method, you should know what the class's members are.

share|improve this answer

In my work I mostly rely on google-style. But generally, it fully depends on a place where you work and what standard they use.

share|improve this answer
I feel bad about this, but I also feel compelled to downvote anyone recommending the garbage which is the Google C++ guide. –  Puppy Aug 2 '12 at 3:39
Any constructive arguments would be appreciated! –  Ivan Kruglov Aug 2 '12 at 4:16
It's pretty common knowledge. I don't actually have a reference on hand. I'm sure I can convince someone else from the C++ lounge to find the list for you. But it's extremely bad and should never, ever be used by anyone - unless you're at Google, that is. –  Puppy Aug 2 '12 at 4:19
Can anyone justify why this is crap ? –  Phoenix Aug 2 '12 at 10:30
