C# naming conventions (is m_varName used?)

  • Thread starter Thread starter Zytan
  • Start date Start date
Am 28 Feb 2007 08:47:32 -0800 schrieb Zytan:
Is the m_variableName used for data members in C# classes? Since
everything is in a class, it seems that it becomes pointless.

What is the general naming conventions?
What are your personal thoughts?

I've been using m_variableName, but I think I'm going to drop it.

I've also been prefixing classes with clsMyClassName, and forms with
frmMyFormName, abd buttons with btnOK, btnCancel, etc, which all makes
sense. Especially for the classes to avoid name clashes.

Zytan

Hello Zytan,
not everything is in a class. Local variables, e.g., are not.
OTOH, the members of struct Point { int x, int y } probably should not
receive a prefix either.

To find a good convention, ask yourself the following questions:
- What do you want to express in addition to the name?
- Do you want to use case as a distinguisher?
- Do you want to prefix or postfix?
- What are the abbreviation rules?
- Do you want to use underscores?

In addition, think of the following:
- Intellisense issues
- human readability

My 2 cents...
Paule
 
Not at all. FxCop is unreliable and indeed way too fussy, usually
over random irrelevant issues. Most of its warnings have little to do
with code quality, and much with the personal preferences of the
tool's authors. But Zytan will soon discover that for himself...

No he won't, because he is not that concerned. :) I just wanted to
know some general ideas, which this thread has shown me. So, thanks
everyone. FxCop is beyond anything I need at this time.

Zytan
 
I think it started in C++, meaning "member".

Ah, I do recall now, although I see it more common in VB than in C++
(the m_). The C++ world I know use _ for class private members, and
g_ for globals. But variations happen in the world as it should
be ;-)

Quoc Linh
 
Most developers invent their own style. But if you
are working in a team, you need acceptable standards,
not only for nomenclature.

Don't prefix (or suffix) underscores ( _) terrible habit that.
Be consistent.

Adrian.
 
Don't prefix (or suffix) underscores ( _) terrible habit that.

Do prefix underscores for private class variables. Wonderful habit,
and makes it easy to find private identifiers with IntelliSense!
 
Do prefix underscores for private class variables. Wonderful habit,
and makes it easy to find private identifiers with IntelliSense!
--http://www.kynosarges.de

I concur Chris.

Adrian, how do you named your private class variables? For me, it's a
must to distinct them otherwise my developer life would be miserable.

Quoc Linh
 
I concur Chris.

Adrian, how do you named your private class variables? For me, it's a
must to distinct them otherwise my developer life would be miserable.

Quoc Linh

private int myVariable;

public void f() {
int localInt = 0;
this.myVariable += myVariable;
}

I've had standards that insisted that member variables be prefixed
with m_, method args with a_, and local variables with l_. Every new
acquisition brought code done with a different standard. I dispense
with prefixes whenever I can.
 

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

Back
Top