Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.






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

Click here to go to article


pho said:

i would even do

sum += line.CalculateTotal()

# January 21, 2009 11:19 AM

Dave said:

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?

# January 21, 2009 3:03 PM

DigiMortal said:

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.

# January 21, 2009 3:51 PM

mel said:

Great, but why stop there?

public decimal Sum()


return _lines.Sum(line => line.CalculateTotal());


# January 22, 2009 5:59 AM

Jason SHort said:

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.

# June 15, 2009 12:16 AM