Make it better when you can
I personally believe in the boy scout rule for Engineers
Always leave the code better than you found it
If everyone said - the code was bad when I started working on it and there were no tests, so I am going to do my job of adding this new feature and I’ll just leave it the way it is - we will never have clean code.
Imagine working on a new version of an existing class. You duplicate the class and notice that there were no tests for the previous version. You now have two choices:
- Build your new class and start using it everywhere the old one was used, and hope that every branch of your new class will get test coverage from some usage upstream or
- Add full test coverage for your new class and then use it everywhere the old one was used
The first option sounds like the easiest. Obviously you’ll spend less time building your new class because you do not have to write any tests specific to it. The problem is with the “hope” part of it. The hope that your class will get test coverage from some usage upstream. IMHO, this is a dangerous approach. Developing the skill of saying - sure, whoever wrote the old class did not think about tests, but I will - takes a lot of practice.
The same principle applies everywhere. You can leave the society the way it is and not fix the problems or you can choose to fix it. While I agree with the statement - if it’s not broken, let’s not fix it - it’s important to do things the right way when you have the opportunity to start fresh.