Thursday, April 05, 2007

A c# coding annoyance

One thing that's been annoying me a lot recently is the block comment for c#. Sure it's nice and easy to highlight everything and use the shortcut ctrl+k, ctrl+c, but then the whack whack is put all the way on the left. If a curly brace changes after that then the autoformatting tabs it over to put the whacks in the position within the block of code.

For example

public void DoSometing()
{
if( test() )
{
if(true)
{
...Code goes here.
}
}
}


When commented out it looks like this.
public void DoSometing()
{
if( test() )
{
// if(true)
// {
// ...Code goes here.
// }
}
}


After adding some code it looks like this.
public void DoSometing()
{
if( test() )
{
// if(true)
// {
// ...Code goes here.
// }
}
else
{
... addidional code goes here.
}
}


This becomes annoying because the code that is commented gets pushed further to the right. I would much rather that the autoformatter leave left justified comments left justified. It doesn't have to be smart about where the spacing falls into line. If the block is uncommented, then the code can be repositioned to fit correctly. Any comment that is not completely left justified could be formatted, but it doesn't have to format the left justified comments.

No comments: