3 ms·
My favorite anecdote on code removal comes from using Sonar, a static code analysis tool. At a previous job, a pretty smart architect decided that Sonar was a
by hibikir 13y ago
My favorite anecdote on code removal comes from using Sonar, a static code analysis tool.
At a previous job, a pretty smart architect decided that Sonar was a pretty good tool to gauge code quality. He wasn't wrong. However, as a way to improve code quality, management decided to make the continuous integration server demand 90% test code coverage minimum, including branches, and no loss of code coverage over half a percent from maximum, as measured by Sonar.
So I inherited a large, rather terrible application, which included a whole lot of UI code using Swing. Swing has it's qualities, but being easy to write meaningful tests for isn't one of them. So my predecessors often left some chunks of frontend relatively untested, while making sure large amounts of business logic was well tested. So to keep the application in order, I started doing a bunch of refactoring. I cut the size of the backend in half, and all the tests kept passing. But my commits were rejected by the build.
So if you have 10K lines of untested code, and 90K lines of very ugly, badly factored, but tested code, you just couldn't remove 10K of the bad, well tested code, because that would sink coverage metrics.
After much arguing for relaxing the rules, as I didn't think that adding tests after the fact to bad UI code seemed like a good use of our time, I fixed it in the only sensible way I could: Added an extra ten thousand lines of well tested code that didn't actually run in production, but made the metrics happy. Only then I could get the build to pass again.
- warmwaffles 13y agoTerrible, but a necessary evil I guess. Sometimes you gotta just let sleeping dogs lie and start removing unused code as you go.
- kyllo 13y agoHaha. Test coverage requirements + no code review = just begging for this to happen.