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)?

 
 
Nick Keighley
Guest
Posts: n/a
 
      01-02-2011
On Dec 31 2010, 3:30*pm, Leigh Johnston <(E-Mail Removed)> wrote:
> On 31/12/2010 08:54, James Kanze wrote:
>
>
>
>
>
> > On Dec 31, 6:07 am, Ebenezer<(E-Mail Removed)> *wrote:
> >> On Dec 21, 6:44 am, Leigh Johnston<(E-Mail Removed)> *wrote:

>
> >>> On 20/12/2010 18:44, 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?

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

>
> >>> I use the following:

>
> >>> sFoo * *// for static variables
> >>> iFoo * *// for member variables, "i" stands for "instance"

>
> >> Taligent used fMemberName -- I think the f was short for field.

>
> >>> aFoo * *// for function arguments
> >>> foo * * // local variables have no prefix

>
> >> In another recent thread on this topic someone suggested
> >> not putting "warts" on member names but on local variables
> >> since their scope is more limited.

>
> > This goes against another rule I've heard: the length of
> > a variable name should be inversely proportional to its scope.
> > I regularly use names like i and j for loop indexes (and I'd
> > definitely not want to prefex them), but no where else.

>
> Yet another bullshit rule Mr Kanze. *


who rattled your cage?

> Just because "i" is acceptable as a
> local variable name (for loop index) does not suddenly make the
> generalization that "variable name should be inversely proportional to
> its scope" valid.
>
> struct point
> {
> * * * * int x;
> * * * * int y;
>
> };


yes but the unadorned names aren't available. You have to use
thePoint.x or thePointP->x. And then we're back to discussing the
scope of thePoint rather than the scope of point.



 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      01-02-2011
On Dec 31 2010, 4:35*pm, Leigh Johnston <(E-Mail Removed)> wrote:
> On 31/12/2010 16:24, Ebenezer wrote:
>
>
>
>
>
> > On Dec 31, 2:54 am, James Kanze<(E-Mail Removed)> *wrote:
> >> On Dec 31, 6:07 am, Ebenezer<(E-Mail Removed)> *wrote:

>
> >>> On Dec 21, 6:44 am, Leigh Johnston<(E-Mail Removed)> *wrote:
> >>>> On 20/12/2010 18:44, 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?
> >>>>> What member data naming convention are folks using for
> >>>>> their C++ production software?
> >>>> I use the following:
> >>>> sFoo * *// for static variables
> >>>> iFoo * *// for member variables, "i" stands for "instance"
> >>> Taligent used fMemberName -- I think the f was short for field.
> >>>> aFoo * *// for function arguments
> >>>> foo * * // local variables have no prefix
> >>> In another recent thread on this topic someone suggested
> >>> not putting "warts" on member names but on local variables
> >>> since their scope is more limited.

>
> >> This goes against another rule I've heard: the length of
> >> a variable name should be inversely proportional to its scope.
> >> I regularly use names like i and j for loop indexes (and I'd
> >> definitely not want to prefex them), but no where else.

>
> > Jeff Schwab and others have suggested using ii and jj rather
> > than just i and j. *I think that's partly to make variables
> > easier to pick up. *Adding a one character prefix to a one or
> > two character variable gives a length of two or three. *I'm
> > just trying it out at this point.

>
> > Do any impose upper limits for variable lengths?

>
> You are trolling.


no he's making a technical point with which you disagree.


>*The number of characters in a variable name is an
> irrelevant metric; what is important is to have a meaningful variable
> name which has nothing to do with the number of characters modulo any
> coding standard requirement to have a prefix.


I don't agree. I don't think its a one-to-one mapping but longer names
do get to be a pain and short names invite name space collisions.


> A compiler may impose an upper limit on symbol name length.



I worked with someone who liked long names. He ended up with names
that weren't unique because he's exceeded the compiler limit. 31
characters I think
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      01-02-2011
On Dec 31 2010, 12:58*am, Öö Tiib <(E-Mail Removed)> wrote:
> On Dec 30, 11:08*pm, Juha Nieminen <(E-Mail Removed)> wrote:
>
> > Nick Keighley <(E-Mail Removed)> wrote:
> > >> 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).

>
> > > guk! And this leads to the hungarian madness!

>
> > * How does using the 'm' prefix (as opposed to the '_' prefix) "lead to
> > hungarian madness"?

>
> Opposed to underscore suffix. Nothing leads to madness. Usually the
> discussions of code style conventions ... just turn into such
> emotional "ugly", "confusing", "mad", etc. madness. In practice worst
> is lack of consistency. So when gathering team then it is best to
> argue, vote and write it down as policy. Whatever strange it is ... if
> used consistently the code base feels more uniform.


"using different letters for different types of variables" sounds
excatly like an invitation to hungarian. I've just been introduced to
a large hungarian code base and I'm not enjoying the experience.



 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      01-02-2011
On Jan 2, 2:27*pm, Leigh Johnston <(E-Mail Removed)> wrote:
> On 02/01/2011 13:26, Nick Keighley wrote
> > On Dec 31 2010, 4:35 pm, Leigh Johnston<(E-Mail Removed)> *wrote:
> >> On 31/12/2010 16:24, Ebenezer wrote:
> >>> On Dec 31, 2:54 am, James Kanze<(E-Mail Removed)> * *wrote:
> >>>> On Dec 31, 6:07 am, Ebenezer<(E-Mail Removed)> * *wrote


<snip>

> >>>>> In another recent thread on this topic someone suggested
> >>>>> not putting "warts" on member names but on local variables
> >>>>> since their scope is more limited.

>
> >>>> This goes against another rule I've heard: the length of
> >>>> a variable name should be inversely proportional to its scope.
> >>>> I regularly use names like i and j for loop indexes (and I'd
> >>>> definitely not want to prefex them), but no where else.

>
> >>> Jeff Schwab and others have suggested using ii and jj rather
> >>> than just i and j. *I think that's partly to make variables
> >>> easier to pick up. *Adding a one character prefix to a one or
> >>> two character variable gives a length of two or three. *I'm
> >>> just trying it out at this point.

>
> >>> Do any impose upper limits for variable lengths?

>
> >> You are trolling.

>
> > no he's making a technical point with which you disagree.

>
> >> * The number of characters in a variable name is an
> >> irrelevant metric; what is important is to have a meaningful variable
> >> name which has nothing to do with the number of characters modulo any
> >> coding standard requirement to have a prefix.

>
> > I don't agree. I don't think its a one-to-one mapping but longer names
> > do get to be a pain and short names invite name space collisions.

>
> Number of characters in a variable name is an irrelevant metric.


stalemate by repetition of position

>*One
> uses named scopes such as classes or namespaces to avoid "name space
> collisions".
>
> >> A compiler may impose an upper limit on symbol name length.

>
> > I worked with someone who liked long names. He ended up with names
> > that weren't unique because he's exceeded the compiler limit. 31
> > characters I think

>
> Sounds like a **** compiler especially if it didn't warn about truncation..


oh it gave an error because the same variable was declared twice, if I
recall correctly. I just find it amazing someone could hit the limit
without really trying. It allowed longer names it just didn't use the
ones past 32 to determine uniqueness

int z_really_really_long_name_a;
int z_really_really_long_name_b;

except they were even longer



 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      01-02-2011
On Dec 31 2010, 4:24 pm, Ebenezer <(E-Mail Removed)> wrote:
> On Dec 31, 2:54 am, James Kanze <(E-Mail Removed)> wrote:


[...]
> > This goes against another rule I've heard: the length of
> > a variable name should be inversely proportional to its scope.
> > I regularly use names like i and j for loop indexes (and I'd
> > definitely not want to prefex them), but no where else.


> Jeff Schwab and others have suggested using ii and jj rather
> than just i and j. I think that's partly to make variables
> easier to pick up. Adding a one character prefix to a one or
> two character variable gives a length of two or three. I'm
> just trying it out at this point.


I'm not sure I understand the issue. Any decent editor will
allow searching for a complete word i.

> Do any impose upper limits for variable lengths?


Not formally. Common sense seems to suffice in this case
(although I once encountered a programmer who regularly used
names over a 100 characters in length).

--
James Kanze
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      01-03-2011
Nick Keighley <(E-Mail Removed)> wrote:
> "using different letters for different types of variables" sounds
> excatly like an invitation to hungarian. I've just been introduced to
> a large hungarian code base and I'm not enjoying the experience.


It's not out of the realm of possibility that you are simply being
prejudiced and not even trying to actually use the naming convention
used in that code to your advantage (ie. to help you read the code
more easily).
 
Reply With Quote
 
Miles Bader
Guest
Posts: n/a
 
      01-04-2011
Juha Nieminen <(E-Mail Removed)> writes:
>> "using different letters for different types of variables" sounds
>> excatly like an invitation to hungarian. I've just been introduced to
>> a large hungarian code base and I'm not enjoying the experience.

>
> It's not out of the realm of possibility that you are simply being
> prejudiced and not even trying to actually use the naming convention
> used in that code to your advantage (ie. to help you read the code
> more easily).


It's also not out of the realm of possibility that a meteoroid will
flatten your house in the next day. Still, it seems a poor bet.

-Miles

--
Bore, n. A person who talks when you wish him to listen.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      01-05-2011
On Tue, 2010-12-21, Juha Nieminen wrote:
> 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).


It's subjective -- which is why we're having this thread over and over
again!

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
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