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 pageshowhide
explore
- Code Smells6 questions
- Refactoring Discipline6 questions
- Refactoring Catalog Techniques6 questions
- Technical Debt Management5 questions
- Boy Scout Rule & Incremental Improvement6 questions
- Working with Legacy Code6 questions
questions
page 2 of 2How 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?
basics
~20 sDon'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.
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?
basics
~20 sOnly 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.
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?
basics
~20 sDo 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.
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.
basics
~20 sBreak 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.
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?
basics
~20 sFix 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.
showing 31–35 of 35