Slide Statements

Removes smells
Symptom

A function where related statements are scattered with interleaved unrelated work — assignments to logically-coupled variables separated by lines that don't share their concern.

Goal

Related statements sit next to each other; the function reads as a sequence of cohesive sub-steps that are easy to extract.

Before the refactoring

const basePrice = qty * itemPrice;
logPriceCalc(basePrice);
const tax = basePrice * 0.1;
logTaxCalc(tax);

After the refactoring

const basePrice = qty * itemPrice;
const tax = basePrice * 0.1;
logPriceCalc(basePrice);
logTaxCalc(tax);
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Reader must hold partial sub-step state in working memory across unrelated statements; the implicit grouping inside the function stays implicit and obstructs further refactoring.

Tradeoff

Reordering can change behavior if statements aren't actually independent — verify side effects and dependencies before sliding.

Relief

Setup for Extract Function becomes trivial; the implicit grouping inside the function becomes explicit.

Trap

Reordering statements without verifying independence — sliding past a statement with hidden side effects (logging that observes state, time-sensitive read) silently changes behavior.