Vinen, I agree with your sentiment that refactoring (or any change to the code) can add regression defects. That's why I generally prefer to refactor only when I need to do major work in a component. Ex: I'm tasked with porting a set of motor controller code from a previous code base into a new one. This code, while well tested and working in the previous code base, is pretty bad and was written by a junior guy basically learning to program. None of us want to maintain it as is, we don't feel sure when modifying it and debugging any problems (software, mechanical or electrical) is a mess when it gets involved.
Even if no changes are made, I will have to fully validate it in the new code base. So since I'm going to eat that cost I may as well spend a couple days refactoring it so that it's no longer a stumbling block.
Even if no changes are made, I will have to fully validate it in the new code base. So since I'm going to eat that cost I may as well spend a couple days refactoring it so that it's no longer a stumbling block.