3

I've been working in an application with about 100k LOCs and basically We have been reworking features to comply with a new architecture based on a new technology stack. This work is almost finished but we had to keep the old code because we had to guarantee a stable environment in case of critical bugs in the new .

This has lead to a situation where we have a lot of dead code that mixes with a lot of working code thus making difficult to estimate how much time it would take to remove this dead code.

This codebase in particular is very troublesome as it does not have unit/integration testing other than the one generated in the process of reworking the features we migrated to the new architecture and also I think that a great deal of the new code is interwoven with the dead code (by static calls, using the previously thrown exceptions).

What would be a good start point to estimate how long would it take to safely remove the code?

ElderMael
  • 260

3 Answers3

6

How much is your company worth?

No, seriously. How much?

Because Knight Capital failed to practice good housekeeping with their systems. And that led to a glitch that ended with their being acquired at firesale prices.

Either the code is dead, or it isn't. If it is dead, then get rid of it. If it isn't, you need to know what's calling the code and make the necessary changes so you can kill off the old code.

If you don't know for sure that it's dead, then either profile your code or make it throw obnoxious, impossible-to-miss errors when those presumed-to-be-dead code paths are hit.

Estimating time / cost for that removal depends upon how well structured the code is to begin with. If the new code is well isolated from the old code, then it should be a minimal cost to change out. If you haven't isolated your code, then it's hard to predict how tangled things are. The more tangled it is, the higher your costs and time.

3

Each project is going to be different so there is not an effective way to estimate the time to remove dead code. Needing to keep the old code sounds like you lack a quality source control system that allows you to branch.

In any case: Tools like SonarQube can help identify some dead code, but won't find things like a class that is never used. I would suggest tackling a portion of the code by hand with the help of SonarQube and develop estimates as you go. If you work through 20% of the classes and it takes 2 weeks then you can estimate an additional 8 more weeks to do the rest.

Also, having some sort of automated testing will help prevent you find code that is mistakenly deleted faster.

jzd
  • 4,176
0

What if you using a global find and replace entered this into the constructor of every class:

PrintToMyLogFile(this.className);

Run your higher level tests including manual tests. Then delete all of the files that arn't in your log file.

This obviously is going to break some things but you can fix those as you go along. This will ensure that you will be able to remove all classes that are not used.

In reality this probably isn't a great way to go about it and probably has multiple issues that I haven't considered yet.