leading underscore for member names

Discussion in 'C++' started by Walter Tross, Apr 29, 2004.

  1. Walter Tross

    Walter Tross Guest

    Somebody with a very regulatory mind in this newsgroup has written
    that it's better not to use a leading underscore for class member
    names, because names with a leading underscore are used internally by
    compilers (well, not so internally, since they appear in header
    files).
    I personally use the leading underscore (followed by a lower case
    letter), which I consider to be much more readable than the trailing
    underscore.
    My reasoning is that scope resolution works, and if I should get a
    clash with a macro (very unlikely, since macros are usually uppercase)
    it almost certainly would result in something which won't compile
    (could in exceptional cases cause a nuisance when porting to another
    platform, but compared with other nuisances...)
    Am I wrong?
    Walter Tross, Apr 29, 2004
    #1
    1. Advertising

  2. Walter Tross

    Cy Edmunds Guest

    "Walter Tross" <> wrote in message
    news:eek:...
    > Somebody with a very regulatory mind in this newsgroup has written
    > that it's better not to use a leading underscore for class member
    > names, because names with a leading underscore are used internally by
    > compilers (well, not so internally, since they appear in header
    > files).
    > I personally use the leading underscore (followed by a lower case
    > letter), which I consider to be much more readable than the trailing
    > underscore.
    > My reasoning is that scope resolution works, and if I should get a
    > clash with a macro (very unlikely, since macros are usually uppercase)
    > it almost certainly would result in something which won't compile
    > (could in exceptional cases cause a nuisance when porting to another
    > platform, but compared with other nuisances...)
    > Am I wrong?
    >


    Two leading underscores or a leading underscore followed by a capital letter
    are reserved. But one leading underscore followed by a lower case letter
    should be OK. I used to use a leading underscore myself but changed to m_
    when I found out that the "m" meant "member" and not "Microsoft". :)

    --
    Cy
    http://home.rochester.rr.com/cyhome/
    Cy Edmunds, Apr 29, 2004
    #2
    1. Advertising

  3. Walter Tross

    Sumit Rajan Guest

    "Walter Tross" <> wrote in message
    news:eek:...
    > Somebody with a very regulatory mind in this newsgroup has written
    > that it's better not to use a leading underscore for class member
    > names, because names with a leading underscore are used internally by
    > compilers (well, not so internally, since they appear in header
    > files).


    > I personally use the leading underscore (followed by a lower case
    > letter), which I consider to be much more readable than the trailing
    > underscore.


    > My reasoning is that scope resolution works, and if I should get a
    > clash with a macro (very unlikely, since macros are usually uppercase)
    > it almost certainly would result in something which won't compile
    > (could in exceptional cases cause a nuisance when porting to another
    > platform, but compared with other nuisances...)
    > Am I wrong?



    17.4.3.1.2 of the Standard:
    Certain sets of names and function signatures are always reserved to the
    implementation:

    - Each name that contains a double underscore (_ _) or begins with an
    underscore followed by an uppercase

    letter (2.11) is reserved to the implementation for any use.



    - Each name that begins with an underscore is reserved to the implementation
    for use as a name in the

    global namespace.165)



    165) Such names are also reserved in namespace ::std (17.4.3.1).



    Regards,

    Sumit.
    Sumit Rajan, Apr 29, 2004
    #3
  4. "Walter Tross" <> wrote in message
    news:eek:...
    > Somebody with a very regulatory mind in this newsgroup has written
    > that it's better not to use a leading underscore for class member
    > names, because names with a leading underscore are used internally by
    > compilers (well, not so internally, since they appear in header
    > files).
    > I personally use the leading underscore (followed by a lower case
    > letter), which I consider to be much more readable than the trailing
    > underscore.
    > My reasoning is that scope resolution works, and if I should get a
    > clash with a macro (very unlikely, since macros are usually uppercase)
    > it almost certainly would result in something which won't compile
    > (could in exceptional cases cause a nuisance when porting to another
    > platform, but compared with other nuisances...)
    > Am I wrong?
    >


    I use them for the same reason. And you're not wrong provided you stick to
    class members.

    john
    John Harrison, Apr 29, 2004
    #4
  5. Walter Tross

    Walter Tross Guest

    On Thu, 29 Apr 2004 08:45:59 +0530, "Sumit Rajan"
    <> wrote:

    >
    >"Walter Tross" <> wrote in message
    >news:eek:...
    >> Somebody with a very regulatory mind in this newsgroup has written
    >> that it's better not to use a leading underscore for class member
    >> names, because names with a leading underscore are used internally by
    >> compilers (well, not so internally, since they appear in header
    >> files).

    >
    >> I personally use the leading underscore (followed by a lower case
    >> letter), which I consider to be much more readable than the trailing
    >> underscore.

    >
    >> My reasoning is that scope resolution works, and if I should get a
    >> clash with a macro (very unlikely, since macros are usually uppercase)
    >> it almost certainly would result in something which won't compile
    >> (could in exceptional cases cause a nuisance when porting to another
    >> platform, but compared with other nuisances...)
    >> Am I wrong?

    >
    >
    >17.4.3.1.2 of the Standard:
    >Certain sets of names and function signatures are always reserved to the
    >implementation:
    >
    >- Each name that contains a double underscore (_ _) or begins with an
    >underscore followed by an uppercase
    >letter (2.11) is reserved to the implementation for any use.


    I dont'quite understand the double underscore thing, since in your
    writing there is a space between the two underscores. Does it refer to
    a leading AND a trailing underscore or does it refer to two
    consecutive underscores (as I guess it does)?
    I don't use either, in any case, so this does not affect me, I think.


    >- Each name that begins with an underscore is reserved to the implementation
    >for use as a name in the
    >global namespace.165)
    >
    >165) Such names are also reserved in namespace ::std (17.4.3.1).


    Since I only use the leading underscore for my class members, I'm
    safely out of the global namespace, and out of ::std too.

    Maybe I should start the "Leading Underscore for Member Names" (LUMN)
    movement :)

    Walter
    Walter Tross, Apr 29, 2004
    #5
  6. Walter Tross

    Sumit Rajan Guest

    "Walter Tross" <> wrote in message
    news:...
    > On Thu, 29 Apr 2004 08:45:59 +0530, "Sumit Rajan"
    > <> wrote:
    >
    > >
    > >"Walter Tross" <> wrote in message
    > >news:eek:...
    > >> Somebody with a very regulatory mind in this newsgroup has written
    > >> that it's better not to use a leading underscore for class member
    > >> names, because names with a leading underscore are used internally by
    > >> compilers (well, not so internally, since they appear in header
    > >> files).

    > >
    > >> I personally use the leading underscore (followed by a lower case
    > >> letter), which I consider to be much more readable than the trailing
    > >> underscore.

    > >
    > >> My reasoning is that scope resolution works, and if I should get a
    > >> clash with a macro (very unlikely, since macros are usually uppercase)
    > >> it almost certainly would result in something which won't compile
    > >> (could in exceptional cases cause a nuisance when porting to another
    > >> platform, but compared with other nuisances...)
    > >> Am I wrong?

    > >
    > >
    > >17.4.3.1.2 of the Standard:
    > >Certain sets of names and function signatures are always reserved to the
    > >implementation:
    > >
    > >- Each name that contains a double underscore (_ _) or begins with an
    > >underscore followed by an uppercase
    > >letter (2.11) is reserved to the implementation for any use.

    >
    > I dont'quite understand the double underscore thing, since in your
    > writing there is a space between the two underscores. Does it refer to
    > a leading AND a trailing underscore or does it refer to two
    > consecutive underscores (as I guess it does)?
    > I don't use either, in any case, so this does not affect me, I think.


    Greetings!

    My guess is the same, too. I guess it should be "__".
    The space between the underscores exists in the Standard, too. (All I did
    was to copy-and-paste). Maybe it was presented that way for better clarity
    in print versions of the Standard.

    >
    > >- Each name that begins with an underscore is reserved to the

    implementation
    > >for use as a name in the
    > >global namespace.165)
    > >
    > >165) Such names are also reserved in namespace ::std (17.4.3.1).

    >
    > Since I only use the leading underscore for my class members, I'm
    > safely out of the global namespace, and out of ::std too.
    >
    > Maybe I should start the "Leading Underscore for Member Names" (LUMN)
    > movement :)


    We would need to make LUMN pronunciation-friendly (Or it would become a
    crime against humanity: the whole world has to do with a name like TCP/IP)?
    Maybe LUMeN would do the trick!


    Regards,
    Sumit.


    > Walter
    Sumit Rajan, Apr 29, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Axter

    leading underscore

    Axter, Nov 11, 2005, in forum: C++
    Replies:
    10
    Views:
    555
  2. Pete C
    Replies:
    5
    Views:
    410
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Dec 14, 2006
  3. John Nagle
    Replies:
    4
    Views:
    584
    James Antill
    Aug 7, 2007
  4. Ulrich Eckhardt

    With or without leading underscore...

    Ulrich Eckhardt, Aug 10, 2009, in forum: Python
    Replies:
    4
    Views:
    319
    Bruno Desthuilliers
    Aug 11, 2009
  5. Replies:
    10
    Views:
    281
Loading...

Share This Page