Is it better to comment out unneeded code or delete it?
- by Matt Connolly
For web applications under maintenance, assuming you have source control, when you need to remove part of the UI and the associated code, do you delete the code and check in, or do you comment out the old code?
Arguments in favor of deleting: cleaner code, can still see deleted code in source control history, no worrying about refactoring code that might be uncommented some day.
Arguments in favor of commenting: sometimes you need to add the feature back in and the developer adding it back in may not know to check source control history, sometimes the code represents unique functionality that can be a handy reference, seeing it all in one place can help provide clues to deciphering the active code.