I have heard many times that unused code must be deleted from the project. However it is not clear for me \"why?\".
My points for not deleting that are:
It's not enough to check the code still compiles. In C++, if you remove an "unused" implicitly defined method like operator= you're not going to get a compiler error, the class will just silently begin to use a (potentially incorrect) default implementation. In Java or C# the code might be used via reflection. In object-oriented languages, inheritance can play a role (the base class may now be called). In almost any language, another overloaded function may have taken over.
Check the age of the code in version control, not just that it's unused. I've seen code that looked unused but had just been committed, and was actually the first step in another developer's project.
You pay to maintain code:
#include change, introducing a new overload to unused code, leading to a reasonably-sized headache for every engineer on a team of dozens of developers.I'd say essentially all the code the average developer writes becomes unused on a five year horizon so this activity never stops. Don't let this be you; only write high quality and absolutely necessary code.