P
Peter Morris
Okay, this is a vent. Probably the majority of people are going to disagree
with me, but I don't care!
When naming private fields the C# guidelines say to use camel casing
public class SomeObject
{
private SomeOtherObject reference;
}
The problem with this is that if you later wish to convert this to a
property you need to replace all uses of the camelCase identifier and
replace them with PascalCase. Now yes, you can use a refactoring tool, but
really, why?
For protected / public fields you need to use PascalCase because you might
not have access to the code that you need to change should you wish to
convert to a property. This means that when you look at
Name = "Pete";
You are looking at a property or a protected / public field.
name = "Pete";
You are looking at a private field, or a parameter, or a local variable.
if setting it from a constructor I need
this.name = name;
Whereas if you use PascalCase from the start converting to a property looks
like this:
public class SomeObject
{
private SomeOtherObject Reference;
}
becomes this
public class SomeObject
{
private SomeOtherObject reference;
private SomeOtherObject Reference
{
get { return reference; }
set { reference = value; }
}
}
I don't have to change any other code anywhere else at all. When I do a
diff in my version control I see a small area of isloated change rather than
changes scattered all over my class wherever I had to change camelCase to
PascalCase as in the original example (less noise in the diff).
In addition to this when I look at the code
Name = "Pete";
I can tell that this is not a parameter or a local variable. I don't need
to know if it is a field or a property, this is a good thing because only
the owner of the field should use the camelCase field anyway seeing as you
can't make the field private to the property (auto-properties go some way
towards solving this problem).
In a constructor I don't need "this" either
Name = name;
I see many reasons why private fields should be PascalCase, and yet I am
unaware of any advantages of it being camelCased.
In my opinion MS made an error of judgement when defining this specific
standard!
with me, but I don't care!
When naming private fields the C# guidelines say to use camel casing
public class SomeObject
{
private SomeOtherObject reference;
}
The problem with this is that if you later wish to convert this to a
property you need to replace all uses of the camelCase identifier and
replace them with PascalCase. Now yes, you can use a refactoring tool, but
really, why?
For protected / public fields you need to use PascalCase because you might
not have access to the code that you need to change should you wish to
convert to a property. This means that when you look at
Name = "Pete";
You are looking at a property or a protected / public field.
name = "Pete";
You are looking at a private field, or a parameter, or a local variable.
if setting it from a constructor I need
this.name = name;
Whereas if you use PascalCase from the start converting to a property looks
like this:
public class SomeObject
{
private SomeOtherObject Reference;
}
becomes this
public class SomeObject
{
private SomeOtherObject reference;
private SomeOtherObject Reference
{
get { return reference; }
set { reference = value; }
}
}
I don't have to change any other code anywhere else at all. When I do a
diff in my version control I see a small area of isloated change rather than
changes scattered all over my class wherever I had to change camelCase to
PascalCase as in the original example (less noise in the diff).
In addition to this when I look at the code
Name = "Pete";
I can tell that this is not a parameter or a local variable. I don't need
to know if it is a field or a property, this is a good thing because only
the owner of the field should use the camelCase field anyway seeing as you
can't make the field private to the property (auto-properties go some way
towards solving this problem).
In a constructor I don't need "this" either
Name = name;
I see many reasons why private fields should be PascalCase, and yet I am
unaware of any advantages of it being camelCased.
In my opinion MS made an error of judgement when defining this specific
standard!