skip to content

Smells & Refactoring

Recognising when code has degraded and improving it without changing behavior: the smell catalogue, the refactoring moves, technical debt, and surviving in legacy code. Interviewers use it to check that you can improve a codebase incrementally rather than demanding a rewrite.

part ofSoftware design & architectureoverview, primer and where to startread it →
on this pageshow

questions

page 2 of 2

How would you make opportunistic, incremental code cleanup a durable habit across many teams, rather than something that depends on a few conscientious individuals? What mechanisms and signals would you use?

level: principalimportance: nice to knowfreq 18%

basics

~20 s

Don't rely on willpower: automate style, gate only newly changed code so quality can only improve, target effort using change-frequency data, give every area an owner, and make small cleanup commits normal and welcome in review.

open as a page

You must restructure code that has no tests and cannot cheaply get any. What disciplines make editing safe(r) without a safety net, and how do you sequence a large legacy restructuring across a team?

level: principalimportance: nice to knowfreq 30%

basics

~20 s

Only make edits a tool or the compiler can verify: automated refactorings, preserving method signatures, moving code without retyping, one goal per edit, small steps compiled and run often. For big restructurings, work in small always-shippable increments, route new work through a new implementation, and keep the old path live until traffic is moved.

open as a page

How do you carry out Extract Class, Move Function and Move Field across a large, actively-developed codebase without a risky big-bang change — and how do you know the extraction boundary is right?

level: principalimportance: nice to knowfreq 32%

basics

~20 s

Do it in small, always-green steps: create the new class, move one field or method at a time while the old class delegates to it, run the tests each time, and only remove the delegation once every caller has migrated. Never move everything at once.

open as a page

How do you execute a refactoring far too large for one commit, across a team sharing one mainline, while keeping the build green and the system releasable at all times? Address the Mikado Method and the parallel-change (expand-contract) technique.

level: principalimportance: nice to knowfreq 28%

basics

~20 s

Break it into many small commits that each keep the build green. Use the Mikado Method to map prerequisites by trying the change, noting what breaks, reverting, and doing the prerequisites first. Use parallel change — add the new form, migrate callers, remove the old — so old and new coexist while others keep working.

open as a page

Code smells are heuristics rather than rules. How do you decide which detected smells to act on, and when is leaving a smell in place the right engineering decision?

level: principalimportance: nice to knowfreq 41%

basics

~20 s

Fix a smell when it makes upcoming work harder. Weigh how often the code changes, how risky it is, and whether tests protect it. Rarely-touched, stable, or soon-to-be-deleted code can keep its smells — refactoring it costs real money and buys nothing.

open as a page

showing 31–35 of 35