Comparison
Boy scout rulevsRefactoring
Boy scout rule
you went in to fix one bug and renamed the two variables that made the bug hard to see.
Leave each file you touch slightly better than you found it. It works because the code you are editing is by definition the code that gets edited, so small improvements accumulate exactly where they are worth the most. It has one failure mode worth naming in review: a bug fix buried in a hundred lines of tidying is hard to review and hard to revert, so the cleaning belongs in its own commit.
Full entry →Refactoring
you changed the shape of the code all afternoon and the tests never went red once.
Changing the internal structure of code without changing its observable behaviour. The behaviour-preserving part is the whole definition, which is why 'refactor' is misused when it means 'rewrite this bit and probably alter what it does'. Being precise matters in planning, because a real refactor is safe enough to interleave with feature work while a behaviour change needs its own testing and its own rollback story.
Full entry →