Gunnar Kudrjavets

Paranoia is a virtue

The joy of pedantic people - hunting down "TODO:" comments in code ;-)

Because of the recent organizational change we inherited a new code base consisting mainly of C# code. When it comes to the unmanaged code then I usually do the following before even reading any lines of new inherited code:

  1. Make sure that code compiles cleanly with /W4, /Wp64, and /WX.
  2. Enable the following compiler options (if not enabled already): /GS and /RTC1. Then run some subset of tests on the new build in hope of seeing some errors.
  3. Run PREfast or PREfix on the code base and look through every single warning.

With managed code it’s not so easy anymore. Half of the problems typical to C/C++ family of programming languages are suddenly gone. It’s not so straightforward to point out mistakes in other people’s code anymore. But the wickedness in me couldn’t rest and after some brainstorming I suddenly had it!

findstr /s /n /c:"TODO:" *.cs

In our group we open a bug per every "TODO:" comment in the code to make sure that everything is accounted for and nothing gets away before shipping. Quick search in bug database showed that I was the first one to stumble across this and more than twenty bugs later I’m feeling that today was a good day ;-) Sometimes there’s only so much needed for happiness.

On the other hand, if a couple of years ago somebody would have pointed out these "TODO:" comments in my code then I would have definitely answered: “Those who can, do. Those who can't, just complain about other people’s code.” Life is strange sometimes.

Posted: Jun 29 2004, 09:42 PM by gunnarku | with 10 comment(s)
Filed under:

Comments

Bernard Vander Beken said:

One thing I would do is run a static code analyzer (eg the metrics in C# Refactory) and glance through all methods with a high cyclomatic complexity.
# June 30, 2004 3:28 AM

TrackBack said:

# June 30, 2004 6:17 AM

Gunnar Kudrjavets [MSFT] said:

My personal experience with McCabe's cyclomatic complexity has been rather suspicious ;-) We spent some time less than a year ago to review all of the pieces of product code which had cyclomatic complexity > n, but got very little in a return.

To save people some time using Google, here’s a link to the McCabe’s article “Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric” - http://hissa.ncsl.nist.gov/HHRFdata/Artifacts/ITLdoc/235/mccabe.html.
# June 30, 2004 9:30 AM

Paul said:

Nice post! I just ran the "findstr" command on some code that we "thought" was finished and found this hilarious comment:

somefilename.vb:1098: 'TODO: Fix this method now 12/11/2003
# June 30, 2004 11:27 AM

Sam said:

Good idea! How about FxCop? It is being presented as the PREFast of managed code, isn't it?
# June 30, 2004 3:36 PM

Gunnar Kudrjavets [MSFT] said:

Based on my experience (your mileage may vary) to be efficient with FxCop requires decent familiarity with the code base and understanding the reasons behind the design decisions what were made. FxCop checks mainly for conformance to the Microsoft .NET Framework Design Guidelines. Not everyone agrees to some of these guidelines and some of them may be not applicable to your product. For example: we implement our own DOM (Document Object Model) and therefore have zibillion different warnings about naming conventions ;-)
# June 30, 2004 3:44 PM

Bernard Vander Beken said:

Sam, I expect FxCop would not be able to find TODO comments, since it only analyses the resulting assemblies.
# July 2, 2004 7:33 AM

Gunnar Kudrjavets [MSFT] said:

AFAIU Sam's question was not towards using FxCop to find 'TODO:' comments, but rather as an additional step for checking the sanity of freshly inherited code base.
# July 2, 2004 2:01 PM

Polar Watches said:

I desire receiving over a broken heart is usually so easy as following a couple of steps..<br> but its not…

--------------------------------------------

my website is  

http://golfcartbags.us

Also welcome you!

# November 17, 2010 9:58 AM

ipad app maker said:

Variety is the spice of life.

-----------------------------------

# December 22, 2010 4:28 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)