Refactoring: delete unneeded code

It is not a miracle that during coding developers produce code that is later not needed anymore. It is also not a miracle that unneeded code will stay in project files waiting for the day when somebody finds this code useful (again). But this far this code is just sitting there and causing problems to people who look at these modules first time.

 

NB! This blog is moved to gunnarpeipman.com

Click here to go to article

5 Comments

  • i would even do
    sum += line.CalculateTotal()

  • Say you have a dll. The dll exposes a public method. Now lets say you have 20 projects that use that dll. What is the best way to get a list of methods in that dll that nobody is using?

  • If you have source of this DLL then you can perhaps use project references and some code analysis tools to find out unused methods. Maybe Resharper can help you.

    If you don't have source of this DLL then you can still use project reference. You can write your own class that wraps the class in DLL and replace references to that DLL with references to your wrapper class. I'm not sure how good idea it is.

  • Great, but why stop there?

    public decimal Sum()
    {
    return _lines.Sum(line => line.CalculateTotal());
    }

  • You should also add that Code Coverage would show that these lines are not being used. If you have functions with 0 % code coverage for your tests then you know the code is not being used.

    You can also use many Code Coverage tools without Unit Testing if you have some other way to test your applications while running under the tool.

Comments have been disabled for this content.