Hungarian notation and variable names

D

Denny

For most of my variable names, I use Hungarian notation to determine between
one and the other. But what names can I use for public and private
variables? I was using prv_varName and pub_varName but that sounded really
strange. I've seen variable names that begin with _varName. Is that another
possibility?

Den
 
F

Floyd Burger

I've been using _VarName for my private vars that my public VarName property
point to, and _varName for those variables that don't have public accessors.
All this at the class level, anything in the methods use varName.
 
A

Allen Anderson

this is a topic of some debate in the .net community. Many companies
require hungarian for local and member variables but don't use them
for properties.

Some people take whether to use hungarian notation or not as an
article of religous faith and may become abusive if you don't do
exactly what they recommend. Ignore them and use whatever your
particular company has standardized on. Remember however, MS
recommends against using HN for .net.
 
D

Denny

There's no real standard at my company. Since this application is being
written from scratch, I can use any type of notation. I usually use HN for
variables but I want to be able to distinguish between a local variable and
a public property.
 
A

Allen Anderson

Where I work, the standard is that we use hungarian notation for
member "m_", function variables, and local variables. We don't use it
for properties. If I had my say on the member variables I'd probably
just use _.
 
C

C# Learner

Denny said:
There's no real standard at my company. Since this application is being
written from scratch, I can use any type of notation. I usually use HN for
variables but I want to be able to distinguish between a local variable and
a public property.

The standard .NET naming conventions enable you to distinguish between a
local variable and a property:

void Foo()
{
int bar = 5; // local variable
Bar = 5; // property
}
 
C

C# Learner

Denny said:
For most of my variable names, I use Hungarian notation to determine between
one and the other. But what names can I use for public and private
variables? I was using prv_varName and pub_varName but that sounded really
strange. I've seen variable names that begin with _varName. Is that another
possibility?

Hmm... isn't it bad form that you're using public member variables anyway?
 
J

Jared Parsons [MSFT]

Another popular way is to prefix the variable with m_

--
Jared Parson [MSFT]
(e-mail address removed)

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
A

Anders Borum

The standard .NET naming conventions enable you to distinguish between a
local variable and a property:

void Foo()
{
int bar = 5; // local variable
Bar = 5; // property
}

Although this leads to poor readable code. Another thing which is more
important is the casing. I favour Pascal casing for public members, but like
camel casing for private members.

If I recall correctly, this is also what Microsoft recommends.
 
C

C# Learner

Anders said:
The standard .NET naming conventions enable you to distinguish between a
local variable and a property:

void Foo()
{
int bar = 5; // local variable
Bar = 5; // property
}

Although this leads to poor readable code. [...]

How do you mean?
 
J

Jon Skeet [C# MVP]

Anders Borum said:
Although this leads to poor readable code.

I think that's debatable. I certainly find it easier to read that than
_bar or m_bar - I can notice the case easily enough to distinguish
between the bar and Bar, but _bar and m_bar give me a mental hiccough
when reading.
Another thing which is more
important is the casing. I favour Pascal casing for public members, but like
camel casing for private members.

If I recall correctly, this is also what Microsoft recommends.

Indeed.
 
A

Allen Anderson

if your saying the bar vs Bar is easier to read then Bar vs _Bar.
heh, thats pretty out there.
 
J

Jon Skeet [C# MVP]

Allen Anderson said:
if your saying the bar vs Bar is easier to read then Bar vs _Bar.
heh, thats pretty out there.

Not really - there are plenty of people who use each of the
conventions. We just have different opinions, that's all.
 
C

C# Learner

Allen said:
if your saying the bar vs Bar is easier to read then Bar vs _Bar.
heh, thats pretty out there.

I don't agree -- the former is easier on my eye.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top