How to refactor while keeping accuracy and redundancy?
Posted
by
jluzwick
on Programmers
See other posts from Programmers
or by jluzwick
Published on 2011-02-08T22:04:16Z
Indexed on
2011/02/08
23:34 UTC
Read the original article
Hit count: 389
refactoring
|code-reuse
Before I ask this question I will preface it with our environment. My team consists of 3 programmers working on multiple different projects. Due to this, our use of testing is mostly limited to very general black box testing.
Take the following assumptions also:
- Unit Tests will eventually be written but I'm under strict orders to refactor first
- Ignore common Test-Driven Development techniques when given this environment, my time is limited.
- I understand that if this were done correctly, our team would actually save money in the long-term by building Unit-Tests before hand.
I'm about to refactor a fairly large portion of the code that is critical. While I believe my code will accurately work when done and after our black box testing, I realize that there will be new data that the new code might not be able to handle.
What I wanted to know is how to keep old code that functions 98% of the time so that we can call those subroutines in case the new code doesn't work properly. Right now I'm thinking of separating the old code in a separate class file and adding a variable to our config that will tell the program which code to use. Is there a better way to handle this?
NOTE: We do use revision control and we have archived builds so the client could always revert to a previous build, but I would like to see if there is a decent way of doing this besides reverting. I want this so they can use the other new functionality delivered in the new build.
Edit: While I agree I will need to write Unit Tests for this, I don't believe I will capture everything with them. I'm looking for ways to easily be able to revert to the old, functional code should anything happen. While I know this is a poor practice, I'm planning on removing this code after our team can guarantee that the new code works to the same standards as the old.
© Programmers or respective owner