views:

55

answers:

2

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?

+3  A: 

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.

John Saunders
I won't edit this, but didn't you mean: All code is legacy code _after_ it is no longer used
Henk Holterman
Thanks for your answer! This seems reasonable. I tried searching to make sure that I would not ask a duplicate question, but I suppose I did not search for the correct combination of words.
DoryuX
@Henk: "legacy" means "left over from the previous generation". This is as distinct from "trash we don't care about any more". At the speed of today's computer industry, everything is legacy code, until it is actually discarded, at which time it is "trash we don't care about any more".
John Saunders
+2  A: 

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!

John M. P. Knox