January 15, 2015

Eliminate dead codes to avoid extra code maintenance

Dead/unreachable codes and member variables:

While working with large projects, silly mistakes are common and those may cause memory or performance issues. Developers used to write method and later some methods either they change or comment. This generally happens in case of frequent requirement change. If you have commented the method and function call then there is –“no comment”. But in case you have commented method call and you haven’t commented method definition, or method defined but never used, or variables declared but never used, what about the memory occupied by instance of such class? These codes called as dead codes or in general unreachable codes. Generally, Visual Studio does provide blue under line for unused variables but they have no such facility to unused methods.

The problem with these are- more about that you have to care and maintain extra code that is not in use. Also typically when you are about to delete an unused code elements, this might provoke asking questions which lead to interesting answer and even bug finding. Is it simple to handle all these for large projects where hundreds of classes designed and thousands of lines coded? NDepend provides to eliminate such issues within a minute.

Here, I have defined two variables and one method but never used those. And these we can call it as dead codes. NDepend installed Visual Studio provides a red bubble on bottom right, on click to this a window will popup which lists out all dead codes.

Or, in alternative way: