Our project has had enough time lately to really focus on some good clean up around the codebase. The project has been under major development for well over a year with plenty of people having worked on it so I find it an interesting experience to see from a high level how things are. FxCop helps us to a certain degree but here’s some very simple metrics I’ve been using to help draw out things to fix:
- ToDo‘s indicating unfinished tasks or notes made by other people. Each represents a signpost that forces people to pause or question what’s there. Each should be considered individually and should be completed, or deleted where possible. Resharper makes it even easier to find them with their TODO Explorer. Our project had a total of five of them.
- Ignored tests are large potential sources of problems, indicating that code could be untested, or a test is not providing the feedback that it should be. There tests should be rewritten, implemented or deleted if they are no longer needed so people don’t need to maintain them. Our project’s grand total… 12 out of 2390.
- Commented code is an obvious code smell, often created by many different reasons (the trick, like the above items are to find out why they’re there). Sometimes the code surrounding the comment may not be readable enough for someone to follow through and that’s easy to fix by applying a variety of refactoring techniques. Other times, commented code may be out of date and is left there because someone wanted to show how something is different – I would use refactoring such as extract method or variable, rename method or variable to help give additional context to get rid of the old code as it’s more important for people to understand what is working now more so than what it is. As a last resort, comments may be there to help explain to other developers why something is there and may be a pragmatic solution to an otherwise convoluted context. These should be exceptional and I would be greatly concerned if these were everywhere. My metric for this was very high, at 6730 lines out of 173122 lines of code although I think most of them are the .Net designer generated code for Winforms and ASP.Net pages.
Overall I was surprised at how little there was to fix with these considering how quickly the codebase has been moving and how many developers have been involved. It’s great to see everyone living the values and I think it shows in the quality of the software.