Brad Abrams has given us a taste of Microsoft by showing us their
internal coding guidelines. There are some interesting things, and
overall it answers a lot of questions that new developers my face. For
the record here are my personal coding habits, which by default are my
companies coding standards.
namespace Company.Product.Component {
public class Test {
private int _myInt;
private string _myString;
public int MyInt {
get { return _myInt; }
set {
_myInt = value; }
}
public string MyString {
get { return _myString; }
set {
_myString = value; }
}
public
Test() {
}
public void MethodA(string
myArgument) {
_myString = myArgument;
}
private void MethodB() {
//Do Something Here
}
}
}
I consider this style a work in progress, and I'm always tweaking
things
as I find better or new ways to do things but overall it works pretty
well. The code uses 2 spaces for an indent and no tabs, unless it's
html/xml.
Private members use the '_' prefix because 'm_' is just too much and
only using casing to distinguish between variables is a bad practice
that will get you in trouble if you ever work in a case insensitive
language like VB.net.
Optional braces are always required, all if statements, no matter how
simple must have braces and this includes switch statements as well
(which I guess is pretty rare).
There are, however, a few things that I haven't quite nailed down
yet, the worst offender being asp.net control names. Right now I'm
using a quasi-post-fix-hungarian sort of thing by appending the control
type to the name ala nameTextBox, userRepeater, etc. This is very
clunky, but prevent naming collisions where you could have a control, a
private member, and a local variable all with the same or similar
names. Of course I wrap
my asp.net controls in a nice member variable to make things
simpler. If anyone has a better naming scheme I'd love to here about it.