Code conventions

During the years I’ve seen a lot of different code convention documents, and they’ve all been huge and inaccessible. No-one ever read them through, and even if you did you couldn’t possibly keep all of it in mind all the time.

Anyway, since there was no such document here at Observer when I started, one of the tasks I was given was to set one up. I’ve just started working on it, and even though I’m mostly just referencing other things, such as the Microsoft naming guidlines, the document is already growing out of proportion..

Something I still can’t really decide on is how to write private field members that relate to public properties. I’ve seen two ways of doing it:

private string _myProperty;
public string MyProperty {
get { return _myProperty; }


private string myProperty;
public string MyProperty {
get { return myProperty; }

Sometimes I kind of like the underscore prefix way. Mostly because it makes it a little bit easier in the constructor since you can put:

public MyClass(string myProperty)
_myProperty = myProperty;

instead of having to use the “this” pointer:

public MyClass(string myProperty)
this.myProperty = myProperty;

However, I think it looks a bit crappy, don’t you? Underscores really aren’t the nicest characters around, and I thought we were moving away from having weird prefixes on our variables..?

There are quite a few different discussions out there on this topic..
Some agree with me, some don’t

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About Me

Consultant, Solution Architect, Developer.

Do note that this blog is very, very old. Please consider that before you follow any of the advice in here!


%d bloggers like this: