Posts Tagged ‘c#’

h1

Coding Styles and Standards

July 5, 2009

At my current engagement, recently, we have decided to start making our coding standards more uniform and so some of the guys got together and decided that from now on, we shall no longer prefix private member fields with an underscore “_” and will just use lower case.

So for example the following property:

private string _foo = null;

public string Foo

{

get

{

Return _foo;

}

}

would be written like this instead:

private string foo = null;

public string Foo

{

get

{

return foo;

}

}

I thought it was a much nicer coding style in terms of pure cleanliness of the code. It seemed more pleasurable to look at. Today on a separate project I am working on, I spent 1.5 hours debugging the following mistake because of this practice. Let’s see how quickly you can find the error

Now, I’m sure you found the error quite quickly especially because I have specifically given you the context of the problem but as you can Imagine, this is not terribly hard mistake to make. I know I have learnt my lesson on the importance of clear code > pretty code. I would be interested in hearing what others have to say about this.

Advertisements