What are the preferred du jour naming conventions for C ++?

I am very confused looking at the boost and stl library and then looking at examples of people. It seems that the names of the uppercase letters are interspersed with all lowercase letters, separated by underscores.

What exactly needs to be done these days? I know that the .NET world has its own set of conventions, but it seems to be completely different from the C ++ realm.

+3
source share
4 answers

What kind of worm did you discover.

The C ++ Standard Library uses underscore_notation for everything because it is what the C Standard Library uses.

So, if you want your code to look consistent across the board (and don't actually use external libraries), this is the only way to go.

You will see that boost uses the same notation, because often their libraries are considered in future standards.

In addition, there are many conventions that typically use different notations to denote different types of characters. CamelCase is commonly used for custom types, such as classes and typedefs, and mixedCase for variables, in particular, to differentiate the two, but this, of course, is not a universal standard.

There is also a Hungarian notation , which further differentiates certain types of variables, although just mentioning this phrase can cause hostility from some coders.

The best answer, as a good C ++ programmer, is to accept any convention used in the code you are immersed in.

+9
source

There is no good answer. If you integrate with the existing code base, it makes sense to match their style. If you are creating a new code base, you can install simple guidelines.

There are several on Google .

+2
source

This will vary by library and organization.

For the developer utility library that I create, for example, I include friendly shell modules for various conventions-style conventions. For example, the MFC wrapper module uses the notation 'm_typeMemberVariable' for members, while the STL wrapper module uses the 'member_variable'. I'm trying to build it so that no matter which interface is used, it will have a style typical of this type of interface.

The problem with the universal style is that everyone has to agree and (for example) for every person who hates the Hungarian notation, there someone who does not consider the Hungarian notation distracts from the main value of the comprehensibility of the code, therefore it is unlikely that in the near future a universal standard will appear in C ++.

0
source

Find what you are comfortable with and stick to it. Some form of style is better than no style, and not too dependent on how other libraries do it.

FWIW I am using the Google C ++ style guide (with some settings).

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

-one
source

All Articles