Naming Conventions

C

cmiddlebrook

Hi there,

I keep finding myself getting inconsistent with naming conventions for
things like member variables, class names etc and I just want to find
something that suits me and stick to it. I am wondering if there are
any naming conventions around that are deemed suitable by the general
C++ community. I have googled around and I can't find much - mostly
long lists of hungarian-like prefixes which is not really what I'm
after.

I searched the groups also and found lots of (lengthy) discussions on
the topic and all i want really is just to read a few guidelines to get
some ideas, pick the ones I like and use that. I've looked around in
books like C++ Coding Standards (Sutter), Effective C++ (Meyers) but
they talk about coding practices rather than naming.

Caroline Middlebrook
 
A

Achintya

Hi,

Often the naming convention( part of Coding standards) are formed
locally by oraganisations(Software companies & Universities). Sometimes
these standards are influenced by Software Configuration Management
(SCM) system of the organisation.

-vs_p...
 
K

Kalle Rutanen

Hi there,

I keep finding myself getting inconsistent with naming conventions for
things like member variables, class names etc and I just want to find
something that suits me and stick to it. I am wondering if there are
any naming conventions around that are deemed suitable by the general
C++ community. I have googled around and I can't find much - mostly
long lists of hungarian-like prefixes which is not really what I'm
after.

I recommend the book "The elements of C++ style".
 
A

Alf P. Steinbach

* (e-mail address removed):
I keep finding myself getting inconsistent with naming conventions for
things like member variables, class names etc and I just want to find
something that suits me and stick to it. I am wondering if there are
any naming conventions around that are deemed suitable by the general
C++ community. I have googled around and I can't find much - mostly
long lists of hungarian-like prefixes which is not really what I'm
after.

Good.

Generally you'll have to accept the fact that libraries employ
different conventions, which means some inconsistency no matter what.

However, one common convention is illustrated by the standard C++
library, and another one is the Java convention (exception: Java uses
all uppercase for constants, as a convention inherited from early C,
but that C/C++ convention has always been for macros, _not_ for constants
except where they're expressed as macros).

I searched the groups also and found lots of (lengthy) discussions on
the topic and all i want really is just to read a few guidelines to get
some ideas, pick the ones I like and use that. I've looked around in
books like C++ Coding Standards (Sutter), Effective C++ (Meyers) but
they talk about coding practices rather than naming.

Make what's important to you visually obvious, and all the rest the same.

Personally I prefer to use PascalCase for class names, a "my" prefix for
members (except sometimes boolean members), and a trailing underscore for
templates, with all the rest -- except macros -- in camelCase.

Boost, in contrast, is very template-oriented, almost all templates, and
therefore the Boost naming guidelines reflect that:
<url: http://www.boost.org/more/lib_guide.htm#Guidelines>.
 
R

Rolf Magnus

Hi there,

I keep finding myself getting inconsistent with naming conventions for
things like member variables, class names etc and I just want to find
something that suits me and stick to it. I am wondering if there are
any naming conventions around that are deemed suitable by the general
C++ community.

Yes, there are lots of them.
I have googled around and I can't find much - mostly long lists of
hungarian-like prefixes which is not really what I'm after.

I searched the groups also and found lots of (lengthy) discussions on
the topic and all i want really is just to read a few guidelines to get
some ideas, pick the ones I like and use that. I've looked around in
books like C++ Coding Standards (Sutter), Effective C++ (Meyers) but
they talk about coding practices rather than naming.

Well, by asking such a question, you open a can of worms. Since many aspects
of coding conventions are more a matter of taste than based on facts,
discussions about them often result in holy wars, which is what you are
referring to as "(lengthy) discussions". If you ask 5 people, you might get
8 opinions, or none at all.
I think the exact conventions are not really important. The only important
thing is to be consistent within one project. This might be a bit
problematic if you use external libraries in your program, and those
libraries use different conventions. OTOH, I often tend to encapsulate such
library code behind my own classes.
If you are using external libraries, it might be a good idea to stick to the
naming conventions of the one you're using the most.
 
B

ben

And sometimes by the style employed by the library you use. Really messing
up when libraries of different coding styles are used in one project.
 
B

Bob Hairgrove

Hi there,

I keep finding myself getting inconsistent with naming conventions for
things like member variables, class names etc and I just want to find
something that suits me and stick to it. I am wondering if there are
any naming conventions around that are deemed suitable by the general
C++ community. I have googled around and I can't find much - mostly
long lists of hungarian-like prefixes which is not really what I'm
after.

I searched the groups also and found lots of (lengthy) discussions on
the topic and all i want really is just to read a few guidelines to get
some ideas, pick the ones I like and use that. I've looked around in
books like C++ Coding Standards (Sutter), Effective C++ (Meyers) but
they talk about coding practices rather than naming.

Caroline Middlebrook

What everyone else said. Except for leading underscores, which are a
no-no, it's probably a toss-up in the end.

Leading underscores are to be avoided in user code. These are reserved
for names used in the standard libraries or built-in names defined by
the compiler or its other libraries ("reserved for the implementation"
is how it is worded in the standard).

The company I used to work for had lots of code where private member
variables were always written with leading underscores because the
company's previous coding guidelines said to do so. Wow, that was a
job when we realized that we should change it ... we went in and
tacked an "m" on in front of the leading underscore because it
amounted to the least amount of typing and still conveyed the
necessary information ("m_" for member).

I don't like trailing underscores either because they are often
overlooked in the implementation code. They have a tendency to get
confused with local variables spelled the same except for the trailing
underscore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top