Prefactoring: Clear the Way for Your New Feature

jandeboevrie1 pts0 comments

Google Testing Blog: Prefactoring: Clear the Way for Your New Feature

Testing Blog

Prefactoring: Clear the Way for Your New Feature

Tuesday, July 21, 2026

This article was adapted from a Google Tech on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office.

By Rahul Singal

"First make the change easy, then make the easy change." - paraphrased from Kent Beck<br>You're working on a new feature, but the existing code wasn't written with future changes in mind. Trying to force the feature in directly gets complicated fast. One change leads to another, and before you know it you're already a few files deep fixing things you never planned to touch.<br>Prefactoring (short for "preparatory refactoring") is the practice of reworking existing code to make it more suitable for an upcoming change before you actually implement the new functionality. Instead of cleaning up code as an afterthought or trying to force a new feature into an incompatible structure, you restructure the codebase first.<br>Prefactoring helps you:<br>Easily implement new features: Restructuring the codebase first ensures your new feature fits naturally into the code.

Speed up reviews: It's easier to review the refactoring and the feature in separate changes.

Avoid bugs: Isolating cleanups from functional logic can help prevent bugs.

Roll back safely: If you need to roll back, it is much easier to revert small, focused changes.

Here is a simplified example of a prefactoring change:<br>Change 1 (Prefactoring)<br>Extract display name helper to remove duplication.<br>Change 2 (Feature)<br>Add middle name support.<br>+ def get_display_name(user):<br>+ return f"{user.first_name}" {user.last_name}

# Profile page<br>- display_name = f"{user.first_name} {user.last_name}"<br>+ display_name = get_display_name(user)<br># Email template<br>- greeting = f"Hi {user.first_name} {user.last_name},"<br>+ greeting = f"Hi {get_display_name(user)},"

def get_display_name(user):<br>- return f"{user.first_name} {user.last_name}"<br>+ return f"{user.first_name} {user.middle_name} {user.last_name}"

You can prefactor a change that is already in review too! If your reviewer suggests a related cleanup during review, you can also extract it into a new base change to keep your current change focused on the feature. Note that not every cleanup needs to be prefactoring: you can do the cleanup in a follow up change if the cleanup doesn’t block your feature, or even in the same change if the cleanup is small enough.

Google

Labels:

Rahul Singal

TotT

Labels

TotT

113

GTAC

61

James Whittaker

42

Misko Hevery

32

Code Health

31

Anthony Vallone

27

Patrick Copeland

23

Jobs

18

Andrew Trenk

13

C++

11

Patrik Höglund

JavaScript

Allen Hutchison

George Pirocanac

Zhanyong Wan

Harry Robinson

Java

Julian Harty

Adam Bender

Alberto Savoia

Ben Yu

Erik Kuefler

Philip Zembrod

Shyam Seshadri

Chrome

Dillon Bly

John Thomas

Lesley Katzen

Marc Kaplan

Markus Clermont

Max Kanat-Alexander

Sonal Shah

APIs

Abhishek Arya

Alan Myrvold

Alek Icev

Android

April Fools

Chaitali Narla

Chris Lewis

Chrome OS

Diego Salas

Dori Reuveni

Jason Arbon

Jochen Wuttke

Kostya Serebryany

Marc Eaddy

Marko Ivanković

Mobile

Oliver Chang

Simon Stewart

Stefan Kennedy

Test Flakiness

Titus Winters

Tony Voellm

WebRTC

Yiming Sun

Yvette Nameth

Zuri Kemp

Aaron Jacobs

Adam Porter

Adam Raider

Adel Saoud

Alan Faulkner

Alex Eagle

Amy Fu

Anantha Keesara

Antoine Picard

App Engine

Arham Jain

Ari Shamash

Arif Sukoco

Bartosz Papis

Benjamin Pick

Bob Nystrom

Bruce Leban

Carlos Arguelles

Carlos Israel Ortiz García

Cathal Weakliam

Christopher Semturs

Clay Murphy

Dagang Wei

Dan Maksimovich

Dan Shi

Dan Willemsen

Dave Chen

Dave Gladfelter

David Bendory

David Mandelberg

Derek Snyder

Diego Cavalcanti

Dmitry Vyukov

Eduardo Bravo Ortiz

Ekaterina Kamenskaya

Elliott Karpilovsky

Elliotte Rusty Harold

Espresso

Felipe Sodré

Francois Aube

Gene Volovich

Google+

Goran Petrovic

Goranka Bjedov

Hank Duan

Havard Rast Blok

Hongfei Ding

Jason Elbaum

Jason Huggins

Jay Han

Jeff Hoy

Jeff Listfield

Jessica Tomechak

Jim Reardon

Joe Allan Muharsky

Joel Hynoski

John Micco

John Penix

Jonathan Rockway

Jonathan Velasquez

Josh Armour

Julie Ralph

Kai Kent

Kanu Tewary

Karin Lundberg

Kaue Silveira

Kevin Bourrillion

Kevin Graney

Kirkland

Kurt Alfred Kluever

Kyle Freeman

Manjusha Parvathaneni

Marek Kiszkis

Marius Latinis

Mark Ivey

Mark Manley

Mark Striebeck

Matt Lowrie

Meredith Whittaker

Michael Bachman

Michael Klepikov

Mike Aizatsky

Mike Wacker

Mona El Mahdy

Noel Yap

Palak Bansal

Patricia Legaspi

Per Jacobsson

Peter Arrenbrecht

Peter Spragins

Phil Norman

Phil Rollet

Pooja Gupta

Project Showcase

Radion Khait

Radoslav Vasilev

Rahul Singal

Rajat Dewan

Rajat Jain

Rich Martin

Richard Bustamante

Roman Govsheev

Roshan Sembacuttiaratchy

Ruslan Khamitov

Saicharan Nimmala

Sam Lee

Sean...

user change feature prefactoring code first_name

Related Articles