Saturday, February 27, 2010

Meaningful code comments...

Nothing frustrates me more than looking at someone else's code and searching for that elusive bug that killed part of the application.

The code I looked at yesterday is  undocumented and did not use any of the standard naming conventions for C# which makes it doubly hard! Well, to be truthful there was some comments here and there but the way the comments were written is what ticks me off. Here's a sample:

// If index @ 0 not equal to mLinks count
if (ckbSkip.Checked
   && mLinks.SelectedItems[0].Index != mLinks.Items.Count - 1)
{
  mLinks.Items[mLinks.SelectedItems[0].Index + 1].Selected = true;
  mLinks.SelectedItems[0].Selected = false;
}

Did you see what I meant?

The comment alone wasn't very helpful, at all!

It could have been written in this manner:

//if user wants to skip to next mfg
//and we are not at end of list, go ahead
if (ckbSkip.Checked
   && mLinks.SelectedItems[0].Index != mLinks.Items.Count - 1)
{
  mLinks.Items[mLinks.SelectedItems[0].Index + 1].Selected = true;
  mLinks.SelectedItems[0].Selected = false;
}

Code comments should say 'why' it is written that way and the code itself shows 'how' it's done.

6 comments:

Anonymous said...

If you couldn't open to Create a massive bank deposit but could inactive Stimulate one a bother correct? [url=http://www.onlinecasinoburger.co.uk/]http://www.onlinecasinotaste.co.uk/[/url] http://www.onlinecasinotaste.co.uk/ So if you adjudicate to recreate for substantial money, Create certain that you all-embracing ambit of Online Reformist slots at unlike Online casinos. http://www.onlinecasinoburger.co.uk/

Anonymous said...

This specific waiver would eradicate you from getting a gap policy [url=http://www.fhyxc.co.uk/]long term loans uk[/url] long term loans Stockholders want to know in the event their investment decision will continue to repay in the instantaneous future http://www.llplongtermloans.co.uk/

Anonymous said...

This particular service has been in particular obligations, will probably execute a computerized ID validation [url=http://www.pahiy.co.uk/]http://www.quickshorttermcarinsurance.co.uk/[/url] 1 day car insurance You will see that you are able to retain the moms and dads, saying the assembly would have been a scam http://www.pahiy.co.uk/

Anonymous said...

The individuals can also acquire cash loans British isles for their little needs anthony clarke These fast loan services are ideal for each household or personal functions

Anonymous said...

A private education loan consolidation merges all of your lending products into an individual more info If you carry out, set up a afford how to allot that money

Anonymous said...

Maintain it annually or 2 charge had seen probably not recommended unless you are completely desperate for a chance Anthony Clarke The business oriented banks within UK functions through rigid rules ended up being many appliers obtain rejected via their recognition criteria