D
Daniel O'Connell [C# MVP]
If you are working alone, the guidelines are your own.Sharon said:Daniel.
I don't want my eyes to be jumping up and down, every time i see an
unknown
field.
If you want to do that, thats your prerogative.
Page long methods are not necessarily a bad thing.
Common guidelines? whose? there are so many of them.
Dot Net guidelines are not the best in my opinion.
Sharon.
If you are working in a group, then the guidelines should be common to the
group.
But if you are working with the public, with anything that will be exposed
to one other person, I think you should strive to use the library guidelines
MS has already provided, everyone already knows them and implicitly
understands them. Serious deviation from those standards are usually enough
for me to decide to find a library which was written cleaner. Also, naming
like this carries the stigma of someone who isn't of the .NET mindset and
reduces faith in code in some cases. I don't want to be offensive, but when
you first examine a library the method names and parameters are going to be
the first thing you see. If you see java or C++ style naming, the first
thing that jumps to mind is that the library may have been developed like it
was java or C++, which as time and experiance has shown, is almost always a
bad thing(direct java ports of applications, in general, turn out to be
pretty off the mark). You get idiosyncratic behavior...things don't mesh
together. You get ".NET stuff" plus this very apparent, very ugly "other
stuff" mixed in your code. Even if the developer writes good, .NET code, the
method, class, namespace, property, and parameter names are still going to
make that class and its usage stand out. Its going to seriously disrupt the
flow of the code. Even your own code is going to exhibit this becase the
framework classes all follow a different convention:
System.String myString = "whatever";
myNamespace.MyClass myClassInstance = new MyClass();
myString.ToString();
myClassInstance.ToString();
myClassInstance.weirdMethodName();
As for unknown fields...I don't think I've ever worked on a method where I
didn't take the time before starting the method to consider the parameters,
even when modifying. A parameter defines, in part, the behavior of the
method, if you don't know the parameters you probably aren't going to get
the method implementation right. Its one of the first things I look at:
description, method name, return value, parameters, attributes, header
variables(those variables that were important enough or used enough to be
defined in the first..oh, 3-10 lines or so of the method, depending on
method length), then on through the code.
Daniel O'Connell said:Which breaks common guidelines; other people have to deal with this, unlike
your fields. I would frown on this practice, personally. If a method is too
long to be able to glance and see which variables are parameters, then your
methods are too long.
Sharon said:One more thing...
I use p_paramName to distinguish between parameters and other method
fields:
//methods
public string MyMethod(int p_id)
{
string tempName = null;
tempName = somehtin.......
return tempName;
}
public class MyClass
{
//members
private int m_count = 0;
private string m_name = null;
//properties
public int Age
{
get{return m_count;}
set{m_count = value;}
}
//methods
public string MyMethod(int id)
{
string tempName = null;
tempName = somehtin.......
return tempName;
}
}
The c# code style guide that I follow suggests that class variables
(fields)
be coded with camel casing, like this:
int recordId;
string name;
It also suggests that variables within methods and method parameters use
camel casing, like this:
void SetName(int id, string newName)
{
recordId = id;
name = newName;
return;
}
This is all fine and dandy, but some of my methods are getting a bit
difficult to read. It's hard to differentiate between class fields (that
have a class-wide scope) and method variables (that have a method-wide
scope). I've started to use the "this" keyword with class variables,
example:
void SetName(int recordId, string name)
{
this.recordId = recordId;
this.name = name;
}
BUT, when you do that, you start to get really long lines of code. Here's
a
real line of my code that exhibits this problem:
this.currencyManager = (CurrencyManager)
this.grdPerson.BindingContext[this.dataView];
I'd love to know what other c# developers do.
Thanks!
Patrick