Skip to main content

Refactorings should be small

When refactoring code, try and make each change as small as possible.

Just renaming a variable to something easier to understand is a valid refactor.

So is extracting a small method or moving logic to another class.

I recently make some refactoring commits to my website and, rather than squashing them, I pushed them to show how simple refactoring can be.

It's easier to see and review each refactor separately in its own commit instead of in one large squashed commit.

It's also easier to keep the code in a working state if the refactors are smaller.

If you break the code whilst refactoring, get back to a working state as soon as possible - even if it means resetting back to the last working commit.

Don't keep making changes - it will be harder to get back to a working state.

About me

Picture of Oliver

I'm an certified Drupal Triple Expert with 18 years of experience, a Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.