473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Naming Convention help - Beyond the basics?

Here is a little problem I've run into, and none of the naming
conventions have helped... Ever since I switched from C to C# and
FxCop, I've going crazy trying to fix some style issues.

I have 3 major issues...

---------

Let's say I have a class called Parameter.

In another class, I want to define a method taking a Parameter.

public void Foo(Parameter ???) {}

The problem is, I'm getting writer's block trying to come up with what
to call the passed variable!

Here's a poor style solution - you have a variable that's one case off
from the class:

public void Foo(Parameter parameter) {}

Here's another poor style solution - you have a variable that's an
abbreviation, and FxCop hates that:

public void Foo(Parameter param) {}

So... What do I call it? Are there generic names that people typically
use, such as "item" or "value"? Are there lists of generic names out
there?

---------

On a similar note... Let's say I have a constructor and a property...

private string _name;
public string Name {get {return _name;} set{_name = value;}}
public Foo(string name)
{
Name = name;
}

I know this is bad form because you have a single case difference, but
I can't always think of a better way of naming things. What can I do?

---------

Finally...

public void IsValidString(string ???)

I want to run a test on a string... What is a good name to call the
passed variable? "testString" won't work, because that's a holdover to
Hungarian notation. "test" sounds too banal... Any suggestions?

---------

Please help me with my style!
- Phillip
Sep 1 '06 #1
3 1361

Just make sure you use the same technique for casing every time.

I also always keep global variables like so:
MyClass _myClass;

Local variables are the same, except no underscore.

When I have an array i'm naming, i just try to pluralize whatever word
it is. If i cant pluralize the word, then i try to find a similar word
that i can. This way i know there is more than one.

I try not to append datatypes onto the variable name, this just adds
extra typing when you can easily mouseover the variable (if in an IDE)
and see what its type is.

thats my 2 cents

Phillip Conrad wrote:
Here is a little problem I've run into, and none of the naming
conventions have helped... Ever since I switched from C to C# and
FxCop, I've going crazy trying to fix some style issues.

I have 3 major issues...

---------

Let's say I have a class called Parameter.

In another class, I want to define a method taking a Parameter.

public void Foo(Parameter ???) {}

The problem is, I'm getting writer's block trying to come up with what
to call the passed variable!

Here's a poor style solution - you have a variable that's one case off
from the class:

public void Foo(Parameter parameter) {}

Here's another poor style solution - you have a variable that's an
abbreviation, and FxCop hates that:

public void Foo(Parameter param) {}

So... What do I call it? Are there generic names that people typically
use, such as "item" or "value"? Are there lists of generic names out
there?

---------

On a similar note... Let's say I have a constructor and a property...

private string _name;
public string Name {get {return _name;} set{_name = value;}}
public Foo(string name)
{
Name = name;
}

I know this is bad form because you have a single case difference, but
I can't always think of a better way of naming things. What can I do?

---------

Finally...

public void IsValidString(string ???)

I want to run a test on a string... What is a good name to call the
passed variable? "testString" won't work, because that's a holdover to
Hungarian notation. "test" sounds too banal... Any suggestions?

---------

Please help me with my style!
- Phillip
Sep 1 '06 #2
Phillip Conrad wrote:
Let's say I have a class called Parameter.

In another class, I want to define a method taking a Parameter.

public void Foo(Parameter ???) {}

The problem is, I'm getting writer's block trying to come up with what
to call the passed variable!

Here's a poor style solution - you have a variable that's one case off
from the class:

public void Foo(Parameter parameter) {}

Here's another poor style solution - you have a variable that's an
abbreviation, and FxCop hates that:

public void Foo(Parameter param) {}

So... What do I call it? Are there generic names that people typically
use, such as "item" or "value"? Are there lists of generic names out
there?
I would use p or param.

Methods should not be longer than you can easily read the entire
method and then it should not matter much what the name is.

If your project has a coding convention follow that. Always.
On a similar note... Let's say I have a constructor and a property...

private string _name;
public string Name {get {return _name;} set{_name = value;}}
public Foo(string name)
{
Name = name;
}

I know this is bad form because you have a single case difference, but
I can't always think of a better way of naming things. What can I do?
I belive that:

private string name;
public string Name {get {return name;} set{name = value;}}
public Foo(string name)
{
this.name = name;
}

is very widely used.

Not very pretty. But any C# programmer should recognize it.
public void IsValidString(string ???)

I want to run a test on a string... What is a good name to call the
passed variable? "testString" won't work, because that's a holdover to
Hungarian notation. "test" sounds too banal... Any suggestions?
public void IsValidString(string s)

Programmers are not stupid. And in a 10-25 line method they are
capable of remembering the name of the parameter.

Arne
Sep 2 '06 #3
If Parameter has a specific purpose or type you could prefix it with an
adjective, otherwise I would go with parameter.

I think differentiating by case is really only an issue if the items you are
differentiating are externally visible (so they can be used by languages
that are not case sensitive). Whilst a user may see 'parameter' in
intellisense it should not cause any conflicts.

This applies to your second point also.

I generally use camel case names for member level variables except when the
variable is the private field of a property then I prefix with an underscore
(with the exception of constructors and private setter methods for read only
properties, I should not see an underscore in a method).

I used to use underscore prefixing for all private fields, but then do you
extend it to fields that are classes? Do you then prefix event handlers from
those fields...

Lastly your method name sounds like it is testing to see if the parameter is
a valid string (which it will be if the paramter is a string) you probably
want to test that it is valid as something else (isValidEmail,
isValidName...). As a last resort use isValidText which would lead to a
parameter of text or textToTest.

"Phillip Conrad" <pr**********@gmail.comwrote in message
news:vk********************************@4ax.com...
Here is a little problem I've run into, and none of the naming
conventions have helped... Ever since I switched from C to C# and
FxCop, I've going crazy trying to fix some style issues.

I have 3 major issues...

---------

Let's say I have a class called Parameter.

In another class, I want to define a method taking a Parameter.

public void Foo(Parameter ???) {}

The problem is, I'm getting writer's block trying to come up with what
to call the passed variable!

Here's a poor style solution - you have a variable that's one case off
from the class:

public void Foo(Parameter parameter) {}

Here's another poor style solution - you have a variable that's an
abbreviation, and FxCop hates that:

public void Foo(Parameter param) {}

So... What do I call it? Are there generic names that people typically
use, such as "item" or "value"? Are there lists of generic names out
there?

---------

On a similar note... Let's say I have a constructor and a property...

private string _name;
public string Name {get {return _name;} set{_name = value;}}
public Foo(string name)
{
Name = name;
}

I know this is bad form because you have a single case difference, but
I can't always think of a better way of naming things. What can I do?

---------

Finally...

public void IsValidString(string ???)

I want to run a test on a string... What is a good name to call the
passed variable? "testString" won't work, because that's a holdover to
Hungarian notation. "test" sounds too banal... Any suggestions?

---------

Please help me with my style!
- Phillip

Sep 3 '06 #4

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

Similar topics

27
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
0
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
6
by: dm1608 | last post by:
I'm relatively new to ASP.NET 2.0 and am struggling with trying to find the best naming convention for the BAL and DAL objects within my database. Does anyone have any recommendations or best...
4
by: Sturdy | last post by:
Hi, I'm new to C# and .NET. I'm a first time user of Visual C# 2005 Express and have a very basic question. I've looked at several links and lots of docs but can't find any tips on naming multiple...
114
by: Jonathan Wood | last post by:
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...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
8
by: mrashidsaleem | last post by:
Can anyone guide me what is wrong with the naming conventions suggested below? I know that this is not recommended by many (including Microsoft) but I need to know what exactly is the rationale...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.