Refactoring Techniques

As you clean up code and it becomes more testable, it also becomes simpler to extend and drives down the cost of future changes. Here are some techniques I use to refactor code.

Generally, refactoring legacy code starts out at the feature level, so there is some observable behavior that you can write a pinning test against.

Pinning Tests

A pinning test is a very coarse test. It may test a single behavior that takes hundreds or thousands of lines of code to produce. Ultimately you want more tests that are smaller tests than this, but start by writing a pinning test for overall behavior so that at least you have some support in place. Then as you make changes to the code, you rerun the pinning test to verify that the end-to-end ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.