How to deprecate code in WordPress

The codebase of a project is in continuous evolution. We add new features, fix issues, and at some point in the development, we found that some code we wrote in the past is no longer necessary. Under this situation, we may have the temptation of removing this piece of code, but is it right?