>
First, add tests, then do your changesThis can be a superpower.
I once had to replace a PostgreSQL-interfacing layer of a large+complex+important system, and most of the original tests had been lost.
It's the kind of change that could be an existential risk for a company that needs the system to be available and correct.
So I built a comprehensive test suite for the existing PostgreSQL-interfacing layer, tested it, made drop-in compatible API using the new way to talk with PostgreSQL, tested that, and... the entire huge system simply worked with the replacement, without a lot of headache/defects/dataloss/ulcers.
> Before you change code, you should have tests in place. But to put tests in place, you have to change code.
Keep reading. You don't always have to do it in the heroic way the article described in this section. Modularity and backward-compatible interfaces, FTW, when you can. The "Sprout" and "Wrap" techniques that the article describes later.
Also, one complementary general technique that the article didn't get into is that sometimes you can run two implementations in parallel, and check them against each other. There are various ways you can do this, involving which really implementation really takes effect, and what you do if they don't agree. (Related: voting configurations in critical systems.)
> Characterization tests
The test suite not only let me validate the implementation, but the exercise of developing the test suite also helped me understand exactly what I should be implementing in the first place.
Sometimes I had to look at the implementation, to tentatively figure out the semantics, then testing validated that also.
> Use scratch refactoring to get familiar with the code
In reasonable cultures and with reasonable management, or if you don't tell anyone. Otherwise, it's the same kind of risk as the old "throwaway prototype" problem: someone with authority says "looks good; I told the customer/CEO we just need to make these few more changes, and ship it". Or, in popular Agile/Scrum processes, "I thought you already completed the refactor last sprint; why are you doing it again".