Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions for template types?

Traditionally, the names of template types are just a single upper-case letter:

template<class A, class B, class C> class Foo {};  

But I hesitate to do this because it's non-descriptive and hard therefore to read. So, wouldn't something like this be better:

template<class AtomT, class BioT, class ChemT> class Foo {};  

I also tend to think the following would not be a bad idea:

template<class ATOM, class BIO, class CHEM> class Foo {};  

It makes them stand out (and also, it's upper-case letters again). What's your opinion?

like image 797
Frank Avatar asked Mar 28 '09 13:03

Frank


People also ask

What are the naming conventions and syntax when defining classes?

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

What is the meaning of naming convention?

A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.


1 Answers

For C++ templates I have a couple of patterns

If there is just a single template parameter, I name it T (or U,V for nested templates).

When there are multiple parameters and the use is not immediately obvious then I use descriptive names prefixed with T. For example, TKey, TValue, TIdentifiier, etc ... This makes the parameters fairly easy to spot throughout the template usage.

I would avoid the all upper case version though. Most people use all upper case identifiers in C/C++ to represent a macro definition. Repeating that pattern for a template parameter is likely to confuse people down the road.

like image 138
JaredPar Avatar answered Oct 05 '22 23:10

JaredPar