What is the proper etiquette for handling potentially reusable legacy code in large projects?

StackOverflow https://stackoverflow.com/questions/873628

  •  22-08-2019
  •  | 
  •  

Question

I have been wondering what is the best way to tackle this situation. Is the best way to leave the old code in a comment block in case someone decides to add that functionality into the project again, or should this code be deleted for the purposes of keeping the source code clean and readable?

Was it helpful?

Solution

This is a duplicate, but I don't have time to find the duplicates.

This also is not specific to legacy code. All code is legacy code, until it is no longer used.

The answer is: use source control. That's what it's for. The text in your source files should be what's currently being executed. Nothing else.

OTHER TIPS

As long as you are using source control, I think it's better to delete unused code. Leaving commented-out code mixed in with active code "just in case" can leave the file difficult to maintian. If the rest of the code is under active development, chances are that the commented code will quickly get left behind. If the zombie code ever is uncommented it might not work at all, or the resurrected code might cause a difficult-to-detect problem.

I've worked on "do not delete" projects. It was like working in a junkyard. Searching the code made me want to cry. Some methods contained more commented code than compiling code. Madness!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top