Welcome to MSDN Blogs Sign in | Join | Help

Just Coding

Spanish Developer Bits
privateMembers?

How do you name your private members?

camelCased or PascalCased?

I think the use of camelCase syntax to name the private members provides a high level of readibality because you know where you are (Public or private) without to look to the member definition.

However, reading code from GDN, people prefer to use PascalCase for everything. All the documentation I've found talking about this topic, only covers Public members so, I suppose you should have freedom to name your privates as you want, but inside a team a general coding standard is a good thing.

What do you think?

Posted: Friday, February 06, 2004 10:20 PM by rido
Filed under:

Comments

Oddur Magnusson said:

I'd recomend using camelCase for private member and Pacal for public.

some people also prefix private members with "_", but I find it messes up intellisense ;)
# February 6, 2004 10:40 PM

Udi Dahan - The Software Simplist said:

I believe that FxCop requires camelCase. I try to keep my systems as FxCop compatible as possible.
# February 6, 2004 10:50 PM

Tim Marman said:

Ditto (although for readability's sake, not to appease the FxCop gods :)
# February 6, 2004 11:04 PM

Jake Good said:

I tend to use camelCase for private and public and PascalCase for classes .. that's how I can keep things straight..

IMHO
Jake
# February 6, 2004 11:13 PM

Mitch Walker said:

camelCase and I prefix all access to them using "this." to easily identify what is a member versus local, etc.
# February 6, 2004 11:17 PM

William Bartholomew said:

Because I use a m_ prefix I find PascalCase easier to read:

m_firstName
m_FirstName
# February 6, 2004 11:53 PM

Jan said:

I use
_firstName

It works both in C# and VB.NET.
# February 7, 2004 10:01 AM

Jose Luis Calvo said:

# February 10, 2004 4:01 AM

Dennis v/d Stelt said:

camelCased with an underscore in front of it.

_firstName, just as Jan.
# February 10, 2004 10:36 AM

Johnny Hall said:

_firstName for me.

And I don't prefix them with this. either when accessing them.

Public = FirstName
Private = _firstName
local = firstName

That's why I use the underscore, to distinguish between local and private. Without it, it's possible to get clashes and it makes the code more readable (IMO).
# February 10, 2004 11:00 AM

Dave L said:

I prefer _camelCase for private and PascalCased for public
# February 10, 2004 12:10 PM

Frans Bouma said:

_camelCased for privates, PascalCased for public, camelCased for method parameters, PascalCased for method names, class names etc.

It's mandatory you distinguish the private member variables with a '_' or m_ or similar from the properties with perhaps the same name. Also Johnny Hall's arguments are very good.
# February 10, 2004 12:14 PM

AndrewSeven said:

I don't really like the idea of _privateVar but in practice it makes my life easier than privateVar
# February 10, 2004 5:48 PM

George Chernyha said:

camelCase for privates, and method parameters, PascalCase for classes, interfaces, method names, and publics.
# February 10, 2004 5:59 PM

Jason Raneses said:

I understand the rationale behind using an underscore prefix for privates, however, I feel doing so is just as bad as using Hungarian notation in a lot of ways. _firstName does not follow the naming guidelines, nor does m_firstName. By using something as simple as firstName for a private variable, and then having a public property named FirstName, you then also code yourself into a corner because it's not recommended to have public and private members differ only by case. It would be nice to see something formally recommended by the powers that be that adheres to the rules and passes FxCop validation.
# February 10, 2004 7:06 PM

Chris Hynes said:

I use camelCase for private fields, _camelCase for fields that back properties, and PascalCase for everything else.
# February 10, 2004 8:35 PM

Eddie Velasquez said:

m_camelCase for private fields.
# February 10, 2004 8:52 PM

Jose Luis Calvo said:

Rido has post a kind of poll about the naming of private members. Some comments on using PascalCase,

# February 18, 2008 5:14 PM
New Comments to this post are disabled
Page view tracker