Search code examples
version-controlcode-coverage

Do you check in new code that doesn't happen to have any immediate application?


In the process of solving a larger problem I wrote a new class method to compute a property of objects of that class. I referred to standards, I found the appropriate internal library calls to do some of the work for me, I commented it fully and I applied it to a variety of sample objects to validate the results.

Later I realized I could solve the larger problem in an entirely different way. I would not need to call my new method at all. The function might be useful for solving some future problem, but if I check it in today it will immediately be dead code. What do I do with it? Check it in? Check it in but #ifdef'd out? Check it in and immediately make another commit to remove it? Leave it in a git-stash? Just accept the loss and move on?


Solution

  • Don't check in dead code in the production tree. If you think you might have some use for that code some day in the future, check it in to your personal repository.

    Anything that is in the product tree has an associated cost - code review, test coverage, design doc, public API description, thread modeling, maintenance, and so on. Paying that cost for code that is not used means you have less to spend on actual features for your users.