Best Practices for Removing Unused Code

后端 未结 8 1327
花落未央
花落未央 2021-02-07 17:56

I\'d like to know what people\'s best practices are for removing unused code. Personally I\'m a fan of deleting (not just commenting) anything that\'s not currently being used.

8条回答
  •  死守一世寂寞
    2021-02-07 18:28

    A piece of code can have two states.
    Either it is active, functioning and tested, in which case it should be in the source control
    Or it is obsolete in a way that you can't imagine anyone ever wanting to use it anymore, simply because it is obsolete. In this case it should be deleted.

    Not erasing code so that "another developer can find it easily" is a perfectly good reason to keep the code active and compiling. Don't worry about the size of your libraries, the linker removes anything that isn't used.

    If you're erasing code and want to warn others of the code that was there and for the reason it was deleted so they won't do the same mistake again, a good comment can be put in place.

提交回复
热议问题