473,788 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

underscore prefix

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

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 8304
This is olb naming convention for private variables. In new MS naming
convention you should use m_ as prefix for private members
More information can be found here
http://msdn.microsoft.com/library/de...guidelines.asp
or use FxCop to validate
http://www.gotdotnet.com/team/fxcop/

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"mike parr" <mp********@yah oo.co.uk> wrote in message
news:Ox******** ******@TK2MSFTN GP12.phx.gbl...
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

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
I think the guidlines actually discourage use of m_ when it says "Do
not apply a prefix to field names or static field names."

--
Scott
http://www.OdeToCode.com

On Mon, 5 Jul 2004 11:40:41 +0300, "Tamir Khason"
<ta**********@t con-NOSPAM.co.il> wrote:
This is olb naming convention for private variables. In new MS naming
convention you should use m_ as prefix for private members
More information can be found here
http://msdn.microsoft.com/library/de...guidelines.asp
or use FxCop to validate
http://www.gotdotnet.com/team/fxcop/


Nov 16 '05 #3
Nothing magical about it; it's just one of many naming conventions for
private class members. I think the underscore prefix is favored by C++
coders.

--Bob

"mike parr" <mp********@yah oo.co.uk> wrote in message
news:Ox******** ******@TK2MSFTN GP12.phx.gbl...
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

Nov 16 '05 #4
I think prefixing any variable in a strongly typed environment simply adds
clutter. I find the convention of capitalizing public members but not
private is much more elegant. Just my opinion.

Mike

"Rakesh Rajan" <Ra*********@di scussions.micro soft.com> wrote in message
news:F8******** *************** ***********@mic rosoft.com...
Hmm...I have always been in the opinion that whenever we have an exposed member like a public variable or property etc, we should avoid Hungarian
Notation and prefixes of any type. But for private entities, I would use m_
or a prefix... --
Rakesh Rajan
"Scott Allen" wrote:
I think the guidlines actually discourage use of m_ when it says "Do
not apply a prefix to field names or static field names."

--
Scott
http://www.OdeToCode.com

On Mon, 5 Jul 2004 11:40:41 +0300, "Tamir Khason"
<ta**********@t con-NOSPAM.co.il> wrote:
This is olb naming convention for private variables. In new MS naming
convention you should use m_ as prefix for private members
More information can be found here

http://msdn.microsoft.com/library/de...-us/cpgenref/h

tml/cpconnamingguid elines.asp
or use FxCop to validate
http://www.gotdotnet.com/team/fxcop/


Nov 16 '05 #5

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

Similar topics

6
2687
by: jason | last post by:
How do I seperate the "chk_" and "33" in the following string: chk_33 Thanks Jason
5
3137
by: Walter Tross | last post by:
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...
9
3006
by: drhowarddrfinedrhoward | last post by:
I see a number of pages with functions like MM_somefunction(). Where does the MM_ come from? I don't see it in any books I'm studying.
38
4543
by: Astra | last post by:
Hi All Could somebody please confirm that if I change my JS expression test from: if (!(/^*$/.test(document.form1.fred.value))) to if (!(/^*$/.test(document.form1.fred.value)))
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,...
13
3081
by: PromisedOyster | last post by:
Many in our development team have came from a C++ background and are in the practice of prefixing private class variables with an underscore to improve readability and avoid naming collisions with local variables and parameters. This has become our standard. ie private string _name; as opposed to: ie private string name;
18
1484
by: Rob | last post by:
Hi, Would it be safe to prefix private and protected methods and properties with and underscore? Would this cause any issues with other languages? Cheers,
6
1879
by: gara.matt | last post by:
Hi, I was wondering, I've been reading some C++ code written by others, usually libraries and stuff, and I've come across what strikes me as a distinctive style that pervades most of the code I've been reading. What I'm talking about is that some variables are declared with a "_" prefix while others lack it. For example you may find a variable and even functions like int _temp
0
9656
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
10364
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...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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
7517
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
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
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.