14
Slide Statements
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 refactoringconst basePrice = qty * itemPrice;
const tax = basePrice * 0.1;
logPriceCalc(basePrice);
logTaxCalc(tax);Savings
Setup for Extract Function becomes trivial; the implicit grouping inside the function becomes explicit.
Note
Reordering can change behavior if statements aren't actually independent — verify side effects and dependencies before sliding.