By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,547 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Naming Conventions

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
ben
Try to read about Code Complete by Steve McConnell

ben
Jul 23 '05 #2

P: n/a
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...

Jul 23 '05 #3

P: n/a
cm**********@btinternet.com wrote:
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".
Jul 23 '05 #4

P: n/a
* cm**********@btinternet.com:

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>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #5

P: n/a
cm**********@btinternet.com wrote:
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.

Jul 23 '05 #6

P: n/a
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.

"Achintya" <vs********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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...

Jul 23 '05 #7

P: n/a
On 10 May 2005 01:34:51 -0700, cm**********@btinternet.com wrote:
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.

--
Bob Hairgrove
No**********@Home.com
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.