Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you do with unused code in your legacy applications? [closed]

On huge legacy applications it is fairly common to see change in business rules leading to unused code. Is the deleting the best way? or Are there any standards of marking the unused code? SCM does help to get the old code back if needed. Also this is specific to .NET code bases.

like image 475
Srikar Doddi Avatar asked Jun 25 '10 02:06

Srikar Doddi


People also ask

Should unused code be removed?

Deleting dead code is not a technical problem; it is a problem of mindset and culture. There is often the sense that if code is not doing anything, it has no effect, so it's OK to leave it. It is worth keeping in mind that exactly the same reasoning also allows us to remove it: if it's not doing anything, remove it.

Where is the unused code in Visual Studio?

To find unused members with a Code Analysis Ruleset, from the Visual Studio menu select File -> New -> File… -> General -> Code Analysis Rule Set. Uncheck all the rules. There are many rules we don't care about right now – and some we probably won't ever care about.


2 Answers

  1. Check old project into Source Control.
  2. Delete unused code.
  3. Profit!!
like image 104
John Gietzen Avatar answered Oct 27 '22 00:10

John Gietzen


  1. Mark it obsolete. http://msdn.microsoft.com/en-us/library/aa664623%28VS.71%29.aspx
  2. Next cycle, comment the code out & make appropriate remarks. Set a region around the code block so that it collapses nicely & doesn't eat up a lot of visual space.
  3. Next cycle, delete the code.

This way you don't surprise your teammates too badly if you need to deprecate some code that you're assigned to but which they need to make calls to. But allows you to make those needed changes!

like image 36
code4life Avatar answered Oct 27 '22 02:10

code4life