473,549 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Member Variables Naming Convention

I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

Thanks for any comments.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Nov 17 '06 #1
114 7770
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?
I think there are 2 main schools of thought on this. This first is to prefix
it with _. The second is to just make it camel case. I prefer the first
although the second appears to be the MS standard.

Michael
Nov 18 '06 #2
Hi Jonathan,
here is a link to the Microsoft guidelines for naming conventions:
http://msdn.microsoft.com/library/de...guidelines.asp

I follow these.

Mark.
--
http://www.markdawson.org
"Jonathan Wood" wrote:
I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

Thanks for any comments.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Nov 18 '06 #3

Jonathan Wood wrote:
I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

Thanks for any comments.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Camel case.

class TheClass
{
private int theInt;

public int TheInt
{
blah, blah, blah
}
}

--
Tom Shelton

Nov 18 '06 #4
Hi,

Just to be clear, I think Michael means lower camel case. Upper camel case
(Pascal case to some) is not acceptable for variable names.

Personally, I think "m_" and "_" are legacy notations and I find them to be
annoying, without any value. I just use lower camel case everywhere.

--
Dave Sexton

"Michael C" <no****@nospam. comwrote in message
news:uY******** ******@TK2MSFTN GP02.phx.gbl...
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>>I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

I think there are 2 main schools of thought on this. This first is to prefix
it with _. The second is to just make it camel case. I prefer the first
although the second appears to be the MS standard.

Michael

Nov 18 '06 #5
I conform *almost* completely to the Microsoft naming conventions, with one
exception: I use an underscore with Pascal case for class member Fields and
Methods that are private or internal, and Pascal case for class member
Fields and Method that are public or protected. This seems to make it easier
to identify the scope of the Field from the Field name, and lessens the
chance that class member Fields which are private or protected will run
into ambiguity issues with parameters. Example:

private float _Cost;
public float Cost { get { return _Cost; } set { _Cost = value; } }

public void Add (float cost)
{
return cost + _Cost;
}

In the above example, the example names are representative of typically
logical names for what they might represent. Occasionally, the situation
occurs when similarly logical names may appear as both a Field and a
parameter in a method. This way, it is easier to identify the difference
inside the Method block.

While I tend to stick closely to Microsoft guidelines for the purpose of
team development ease, I do take a liberty or 2 (and stick to it
consistently) when I think I may have a better idea (which is very seldom).

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

Any experience you can walk away from
is a good one.

"Mark R. Dawson" <Ma*********@di scussions.micro soft.comwrote in message
news:1D******** *************** ***********@mic rosoft.com...
Hi Jonathan,
here is a link to the Microsoft guidelines for naming conventions:
http://msdn.microsoft.com/library/de...guidelines.asp

I follow these.

Mark.
--
http://www.markdawson.org
"Jonathan Wood" wrote:
>I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

Thanks for any comments.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Nov 18 '06 #6
Hello Jonathan,

Fully support Kevin's point about using "_" that helps to differ private/internal
variables. It is very usefull in codereview, because very often u use simple
text editors for this
JWI was just wondering what naming convention most of you use for
JWclass variables.
JW>
JWUnderscore, "m_" prefix, camel case, capitalized, etc?
JW>
JWHas one style emerged as the most popular?
JW>
JWThanks for any comments.
JW>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 18 '06 #7
Hi Kevin,

You believe that the little value "_" notion provides, if any, outweighs the value of using
standardized naming conventions?

Of course, if you work in an environment where "_" is the accepted standard then it might not be
such a problem, but if you're program is ever touched by anyone else, it might be confusing to them.
Therefore, I don't believe that anyone should take any liberties when there is already
widely-accepted standardization in place.

--
Dave Sexton

"Kevin Spencer" <sp**@uce.govwr ote in message news:Om******** *****@TK2MSFTNG P06.phx.gbl...
>I conform *almost* completely to the Microsoft naming conventions, with one exception: I use an
underscore with Pascal case for class member Fields and Methods that are private or internal, and
Pascal case for class member Fields and Method that are public or protected. This seems to make it
easier to identify the scope of the Field from the Field name, and lessens the chance that class
member Fields which are private or protected will run into ambiguity issues with parameters.
Example:

private float _Cost;
public float Cost { get { return _Cost; } set { _Cost = value; } }

public void Add (float cost)
{
return cost + _Cost;
}

In the above example, the example names are representative of typically logical names for what
they might represent. Occasionally, the situation occurs when similarly logical names may appear
as both a Field and a parameter in a method. This way, it is easier to identify the difference
inside the Method block.

While I tend to stick closely to Microsoft guidelines for the purpose of team development ease, I
do take a liberty or 2 (and stick to it consistently) when I think I may have a better idea (which
is very seldom).

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

Any experience you can walk away from
is a good one.

"Mark R. Dawson" <Ma*********@di scussions.micro soft.comwrote in message
news:1D******** *************** ***********@mic rosoft.com...
>Hi Jonathan,
here is a link to the Microsoft guidelines for naming conventions:
http://msdn.microsoft.com/library/de...guidelines.asp

I follow these.

Mark.
--
http://www.markdawson.org
"Jonathan Wood" wrote:
>>I was just wondering what naming convention most of you use for class
variables.

Underscore, "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

Thanks for any comments.

--
Jonathan Wood
SoftCircuit s Programming
http://www.softcircuits.com


Nov 18 '06 #8
Hello Dave,

What's the most interesting that the widely-accepted standardization is tuned
a little bit to suite company best practice.
I've met the number of cases where "_" was used widely in the big companies
and it gives more pros than cons

DSHi Kevin,
DS>
DSYou believe that the little value "_" notion provides, if any,
DSoutweighs the value of using standardized naming conventions?
DS>
DSOf course, if you work in an environment where "_" is the accepted
DSstandard then it might not be such a problem, but if you're program
DSis ever touched by anyone else, it might be confusing to them.
DSTherefore, I don't believe that anyone should take any liberties
DSwhen there is already widely-accepted standardization in place.
DS>
DS"Kevin Spencer" <sp**@uce.govwr ote in message
DSnews:Om****** *******@TK2MSFT NGP06.phx.gbl.. .
DS>
>I conform *almost* completely to the Microsoft naming conventions,
with one exception: I use an underscore with Pascal case for class
member Fields and Methods that are private or internal, and Pascal
case for class member Fields and Method that are public or protected.
This seems to make it easier to identify the scope of the Field from
the Field name, and lessens the chance that class member Fields which
are private or protected will run into ambiguity issues with
parameters. Example:

private float _Cost;
public float Cost { get { return _Cost; } set { _Cost = value; } }
public void Add (float cost)
{
return cost + _Cost;
}
In the above example, the example names are representative of
typically logical names for what they might represent. Occasionally,
the situation occurs when similarly logical names may appear as both
a Field and a parameter in a method. This way, it is easier to
identify the difference inside the Method block.

While I tend to stick closely to Microsoft guidelines for the purpose
of team development ease, I do take a liberty or 2 (and stick to it
consistently ) when I think I may have a better idea (which is very
seldom).

-- HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com
Any experience you can walk away from
is a good one.
"Mark R. Dawson" <Ma*********@di scussions.micro soft.comwrote in
message news:1D******** *************** ***********@mic rosoft.com...
>>Hi Jonathan,

here is a link to the Microsoft guidelines for naming conventions:

http://msdn.microsoft.com/library/de...rary/en-us/cpg
enref/html/cpconnamingguid elines.asp

I follow these.

Mark.
--
http://www.markdawson.org
"Jonathan Wood" wrote:

I was just wondering what naming convention most of you use for
class variables.

Underscore , "m_" prefix, camel case, capitalized, etc?

Has one style emerged as the most popular?

Thanks for any comments.

--
Jonathan Wood
SoftCircui ts Programming
http://www.softcircuits.com
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 18 '06 #9
On Sat, 18 Nov 2006 09:55:38 -0500, "Dave Sexton"
<dave@jwa[remove.this]online.comwrote :
>Hi Kevin,

You believe that the little value "_" notion provides, if any, outweighs the value of using
standardized naming conventions?

Of course, if you work in an environment where "_" is the accepted standard then it might not be
such a problem, but if you're program is ever touched by anyone else, it might be confusing to them.
As long as the convention is used consistently, reasonable cognizant
programmer shouldn't be confused for very long if at all.
>Therefore, I don't believe that anyone should take any liberties when there is already
widely-accepted standardization in place.
Agreed, if a convention is already in place it should be followed.
Consistency of use should be the 'real' standard for any naming
convention.

regards
A.G.
Nov 18 '06 #10

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

Similar topics

10
3304
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm still learning Python as I develop a medium-sized project. From my previous experience with C++, I've burnt into my mind the notion of information hiding. I'm having trouble understanding to what extent I should follow this policy in my Python code so I thought I'd ask the group. I read from a previous post that to...
60
5002
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this. consistently may make the code easier to understand for someone else, etc. Using "this." makes it immediately clear, for example, that the variable being...
0
7524
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...
0
7451
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...
0
7720
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. ...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7812
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...
0
6048
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...
0
3501
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...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
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.