Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > naming convention for class attributes (member data)?

Reply
Thread Tools

naming convention for class attributes (member data)?

 
 
Marco
Guest
Posts: n/a
 
      12-20-2010
It seems that the most common naming convention for class instance attributes these days (from C++ books) is the trailing underscore. When did this style become the "fashion" leader?

What member data naming convention are folks using for their C++ production software?
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-20-2010
On 12/20/2010 1:44 PM, Marco wrote:
> It seems that the most common naming convention for class instance
> attributes these days (from C++ books) is the trailing underscore.
> When did this style become the "fashion" leader?


Probably at about the same time as it became fashionable to bash MS for
their "Hungarian notation" and their leading 'C' for classes and 'm_'
for members...

> What member data naming convention are folks using for their C++
> production software?


It probably varies from group to group, but I wouldn't be surprised if
most (more than 50%) Windows folks use 'm_' prefix for member data in
their software.

Let me ask you, though, why do you care?

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Goran
Guest
Posts: n/a
 
      12-21-2010
On Dec 20, 7:44*pm, Marco <(E-Mail Removed)> wrote:
> It seems that the most common naming convention for class instance attributes these days (from C++ books)
> is the trailing underscore. When did this style become the "fashion" leader?
>
> What member data naming convention are folks using for their C++ production software?


Who cares? Doesn't matter!

Goran.

P.S. member_ (gcc), m_tpMember (MS, and tp stands for "type prefix"),
FMember (Borland, "F" is for "field").
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-21-2010
On Dec 20, 6:44 pm, Marco <(E-Mail Removed)> wrote:
> It seems that the most common naming convention for class
> instance attributes these days (from C++ books) is the
> trailing underscore. When did this style become the "fashion"
> leader?


Which books? It used to be prevelant, but I've not seen it in
a long time.

> What member data naming convention are folks using for their
> C++ production software?


The most frequent I've seen is an m_ prefix (with s_ for static
members); I've also seen my (with our for statics), and code
which doesn't use any special mark. (In an ideal world, no
special convention should be necessary. The name of the
variable would say enough about it that you'd just know. In
practice, I've not seen a team where everyone was that good at
naming, however, and some convention certainly helps then.)

--
James Kanze
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-21-2010
On Dec 20, 7:04 pm, Victor Bazarov <(E-Mail Removed)> wrote:
> On 12/20/2010 1:44 PM, Marco wrote:


> > It seems that the most common naming convention for class instance
> > attributes these days (from C++ books) is the trailing underscore.
> > When did this style become the "fashion" leader?


> Probably at about the same time as it became fashionable to bash MS for
> their "Hungarian notation" and their leading 'C' for classes and 'm_'
> for members...


Neither are what I'd call Hungarian, and as far as I know, no
one has bashed Microsoft for using a leading C for MFC classes
(in the absense of namespaces when they developed them). What
people do object to is users who put a leading C everywhere,
since that prefix does indicate that the class is in MFC.

--
James Kanze
 
Reply With Quote
 
Öö Tiib
Guest
Posts: n/a
 
      12-21-2010
On Dec 21, 12:19*pm, James Kanze <(E-Mail Removed)> wrote:
> On Dec 20, 7:04 pm, Victor Bazarov <(E-Mail Removed)> wrote:
>
> > On 12/20/2010 1:44 PM, Marco wrote:
> > > It seems that the most common naming convention for class instance
> > > attributes these days (from C++ books) is the trailing underscore.
> > > When did this style become the "fashion" leader?

> > Probably at about the same time as it became fashionable to bash MS for
> > their "Hungarian notation" and their leading 'C' for classes and 'm_'
> > for members...

>
> Neither are what I'd call Hungarian, and as far as I know, no
> one has bashed Microsoft for using a leading C for MFC classes
> (in the absense of namespaces when they developed them). *What
> people do object to is users who put a leading C everywhere,
> since that prefix does indicate that the class is in MFC.


Yes, but Victor did name them as three different decorations of
MicroSoft not as same. I remember plenty of bashing against "Hungarian
notation", first it was ugly itself and while original notation was
for attributing usage of variable MS did indicate type with it.

Using leading C (of MFC) in your own classes feels like using prefixes
Q (of QT) or WX (of wxwidgets) in your own classes, but Visual Studio
code generators and wizards encourage to use C in your own classes.
That was also seriously frowned upon.

None bashing i remember about m_ prefix, but I have also picked up
that trailing underscore for private data members. MS m_ prefixed data
members were often public, I have none as rule. The best idea is
perhaps to agree it with team and to follow what was agreed. It is
cheap to statically check (and even convert between) such conventions.

Oh .... and because concurrency has gone into big fashion static data
members are quite out of fashion. These cause similar synchronization
overhead and scalability issues as all sorts of other singular state.
 
Reply With Quote
 
Drew Lawson
Guest
Posts: n/a
 
      12-21-2010
In article <(E-Mail Removed)>
(E-Mail Removed) writes:
>It seems that the most common naming convention for class instance attributes these days (from C++ books)
>is the trailing underscore. When did this style become the "fashion" leader?
>
>What member data naming convention are folks using for their C++ production software?


I originally scoffed at any such notations. But over time, I've
fallen in with the trailing underscore. When I'm looking at code
that isn't fresh, it is helpful to me to see that a symbol is in
the instance, so I don't get annoyed at not being able to see the
declaration.

As for what I *see* most often, well that would be the leading
underscore. It's like a meme or a code style virus. I see it
everywhere and have (usually) given up on pointing out why it is
ill advised.

--
Drew Lawson | Pass the tea and sympathy
| for he good old days are dead
| Let's raise a toast to those
| who best survived the life they led
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      12-21-2010
Drew Lawson <(E-Mail Removed)> wrote:
> I originally scoffed at any such notations. But over time, I've
> fallen in with the trailing underscore. When I'm looking at code
> that isn't fresh, it is helpful to me to see that a symbol is in
> the instance, so I don't get annoyed at not being able to see the
> declaration.


The problem with a trailing underscore is that it makes code visually
more confusing (especially when the underscore is followed by other
symbols such as dots or dashes). Using a letter prefix is less confusing
(and also gives more possibilities, ie. using different letters for
different types of variables).

> As for what I *see* most often, well that would be the leading
> underscore. It's like a meme or a code style virus. I see it
> everywhere and have (usually) given up on pointing out why it is
> ill advised.


Should suffice to say that the C++ standard frowns on the programmer
using it (IIRC).
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-21-2010
On Dec 21, 12:33 pm, Öö Tiib <(E-Mail Removed)> wrote:
> On Dec 21, 12:19 pm, James Kanze <(E-Mail Removed)> wrote:


> > On Dec 20, 7:04 pm, Victor Bazarov <(E-Mail Removed)> wrote:


> Oh .... and because concurrency has gone into big fashion static data
> members are quite out of fashion. These cause similar synchronization
> overhead and scalability issues as all sorts of other singular state.


Really. Everyone I know still prefers "static int const size
= 42;" over "#define SIZE 42". (In other words, there's static,
and there's static.)

--
James Kanze
 
Reply With Quote
 
Puppet_Sock
Guest
Posts: n/a
 
      12-21-2010
On Dec 20, 1:44*pm, Marco <(E-Mail Removed)> wrote:
[snip]
> What member data naming convention are folks
> using for their C++ production software?


Naming conventions are only important when you
are in a team. In that case, you should get
together with your team and decide what to do.
It's important to keep the team as happy as
can be easily achieved. If a trivial thing
like agreeing on a naming convention will
decrease arguments, I say go for it.

Personally, I can deal with just about any
sensible naming convention. The only things
I will object to are things that interfere
with standard library or compiler convnetions.
If a thing created by the development team
(variable, object, function, class, namespace,
etc. and so on) *looks* like it is one of the
things that "comes with" the compiler, then
I object that it is confusing.

But beyond that, hey. We have good text editors
built into most development environments. I can
deal with a naming convention.
Socks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Naming Convention for ASP.NET BAL/DAL? dm1608 ASP .Net 6 02-24-2006 07:25 PM
WS C3550 naming convention question frishack@gmail.com Cisco 2 02-23-2005 07:29 PM
Which c# naming convention? Rick ASP .Net 1 01-19-2004 11:42 AM
Looking for good naming convention for class attributes Sandeep Sharma C++ 9 01-16-2004 11:49 PM



Advertisments