473,772 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

leading underscore for member names

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?

Jul 22 '05 #1
5 3136
"Walter Tross" <wa****@waltert ross.com> wrote in message
news:ov******** *************** *********@4ax.c om...
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/
Jul 22 '05 #2

"Walter Tross" <wa****@waltert ross.com> wrote in message
news:ov******** *************** *********@4ax.c om...
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.


Jul 22 '05 #3

"Walter Tross" <wa****@waltert ross.com> wrote in message
news:ov******** *************** *********@4ax.c om...
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
Jul 22 '05 #4
On Thu, 29 Apr 2004 08:45:59 +0530, "Sumit Rajan"
<su********@myr ealbox.com> wrote:

"Walter Tross" <wa****@waltert ross.com> wrote in message
news:ov******* *************** **********@4ax. com...
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
Jul 22 '05 #5

"Walter Tross" <wa****@waltert ross.com> wrote in message
news:qb******** *************** *********@4ax.c om...
On Thu, 29 Apr 2004 08:45:59 +0530, "Sumit Rajan"
<su********@myr ealbox.com> wrote:

"Walter Tross" <wa****@waltert ross.com> wrote in message
news:ov******* *************** **********@4ax. com...
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 implementationfor 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

Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1134
by: Tom Blackwell | last post by:
Today I installed the 'mechanoid' package from sourceforge, but the self-test failed. On looking into it, I noticed odd behaviour in the handling of single underscore module names. Importing into the current namespace with 'from' seems to work, but accessing members of the imported module only works if the imported name is qualified by the containing module name. For example: >>> from mechanoid import _mechanoid_Common >>> from...
10
19214
by: Axter | last post by:
Section 17.4.3.1.2 states that each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace. Exactly what defines the implementation? Is it only narrowly defined by the compiler's internal name handling? Or does it also include the library that comes with the compiler? Does it include the OS library as part of the implementation?
4
8304
by: mike parr | last post by:
A few times when looking at code on the net I have seen objects, variables etc prefixed by an underscore. But I've never seen any explanation for the reason for this. What is the reason for doing this? Thanks, Mike
19
3330
by: ok | last post by:
I came across some variable name like __gc_context. I started thinking a bit if I should tell the author of that code that names starting with underscores are reserved for the implementation. I decided not to because it would make me look like somebody who just wastes other people's time instead of finding real bugs. Come on, how serious should we take this rule? This wont ever be an issue
16
3386
by: Jim Langston | last post by:
I know that functions starting with an underscore, or two underscores, are reserved by the compiler/c++ and should not be used by the user and may cause undefined behavior. My question is, how likely is it to actually cause undefined behavior? The reason I'm asking is I'm using a game engine where the sockets code is not working correctly on my computer, but seems to work correctly on everyone elses. I am not compiling the dll myself,...
14
2431
by: Bit Byte | last post by:
I have the following struct: typedef struct { string symbol; string synonym; Synonym(string _synonym, string _symbol) { synonym = _synonym; symbol = _symbol; }
9
2070
by: Joseph Turian | last post by:
Consider this code snippet which doesn't compile: struct DebugOptions { }; class Debug { public: Debug(const DebugOptions options) { _options = options; } private:
5
2174
by: Pete C | last post by:
I was looking at Section 17.4.3.1 and I can't work out whether macro names are also covered by Section 17.4.3.1.2 ("Global names"). I often see preple chastised for using include guards like _INCLUDED_BLAH_H (and I avoid them myself "just to be on the safe side"). But if this is a mistake, then it is an astonishingly common one. There are dozens of well-known libraries in my /usr/include that do it. Is this technically a mistake that...
9
3020
by: jbaranski | last post by:
Access 2003 on XP pro machine... i'm running a crosstab query and an export to a 3rd party company showing different benefit plans for employees; specifically dental, vision and medical pulling the effective dates (date which the plan when into effect). generally the plans all have the same effective date. however in the case they don't 2 lines are returned for the same employee; the first containing, for example, their medical and vision...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.