TL;DR: Default to search-and-replace blocks for changes to existing files: compact, independent of line numbers, and easy to apply strictly (the quoted text must match exactly once). Use whole-file writes for new files and very small ones. Use unified diffs only if your model produces them reliably, applied by context rather than trusted line numbers. Then measure on your own tasks: apply rate, correctness after applying, output tokens and latency, per model, because the best format differs between models.
How to approach it
Compare the formats on cost and failure modes, give a default with reasons, and say how you would confirm it with data and keep it confirmed as models change.
A strong answer
The comparison.
| Search-and-replace | Unified diff | Whole file | |
|---|---|---|---|
| Output tokens | Changed region plus some context | Changed lines plus context | The whole file |
| Fails when | Quoted text not exact or not unique | Line numbers or context slightly off | Model drops or alters unrelated lines |
| Applying | Exact unique match | Patch tool, ideally by context | Overwrite |
| Review | Easy | Easy | Hard: must diff afterwards |
Default and reasons. Search-and-replace for existing files: models quote text more reliably than they count lines, the applier can be strict, and errors are explainable ("found twice; include more surrounding lines"). Whole files for new files, where there is nothing to disturb. Diffs where measurements show the model handles them well.
Measure on your work.
def score(runs):
applied = [r for r in runs if r["applied"]]
correct = [r for r in applied if r["tests_pass"]]
return {"apply_rate": round(len(applied) / len(runs), 2),
"correct_rate": round(len(correct) / len(runs), 2),
"avg_out_tokens": round(sum(r["out_tokens"] for r in runs) / len(runs))}
search_replace = ([{"applied": True, "tests_pass": True, "out_tokens": 420}] * 88 +
[{"applied": True, "tests_pass": False, "out_tokens": 400}] * 6 +
[{"applied": False, "tests_pass": False, "out_tokens": 380}] * 6)
whole_file = ([{"applied": True, "tests_pass": True, "out_tokens": 2900}] * 85 +
[{"applied": True, "tests_pass": False, "out_tokens": 3100}] * 15)
sr, wf = score(search_replace), score(whole_file)
print(sr["apply_rate"], sr["correct_rate"], sr["avg_out_tokens"]) # => 0.94 0.88 416
print(wf["apply_rate"], wf["correct_rate"], wf["avg_out_tokens"]) # => 1.0 0.85 2930
Illustrative numbers with a common shape: whole files always apply but are wrong more often (unintended changes elsewhere) and cost seven times the output tokens; search-and-replace fails to apply sometimes, but those failures are visible and fixable on the next turn.
Make failures cheap. Precise error messages for not found, ambiguous and whitespace mismatches; one retry with the file's current text; then fall back to a whole-file write for small files.
Keep it measured. Re-run the comparison when you change models; formats that suit one model can suit another poorly.
What interviewers probe next
"Can you accept fuzzy matches when the exact one fails?" Only with a guard: a single candidate above a high similarity, shown in the observation so the model can confirm. Silent fuzzy application is how the wrong function gets edited.
"What about structured edit tools (rename symbol, insert after function)?" Excellent where available: they are exact by construction. Language-server refactorings for renames beat text edits.
"Does the format affect review?" Yes: humans review diffs; whole-file outputs need diffing first, and large unintended changes hide in them.
What if?
What if · interview follow-ups
Hold your answer as the constraints change
You chose search-and-replace blocks with a strict applier.
Start here
What if 10% of blocks fail because the model quotes code it remembers rather than the current file?
What does the model have in context?
The file changed since the model read it (its own earlier edit). Return the current text of the region with the error, so the next attempt quotes what is actually there.
Carry it forwardFailures should carry the current text.
Weak answerSwitching to fuzzy matching.
Constraint changes
What if a change touches twenty places in one file?
Is it still an edit?
Use a structured refactoring tool if it is a rename, or a whole-file write if the file is small; twenty blocks multiply the chance of one failing.
Carry it forwardMatch the tool to the change's shape.
Weak answerForcing every change through one format.
Constraint changes
What if a new model scores worse with blocks than with diffs?
Is the format fixed?
Make the format a per-model setting chosen by the measurement on your own tasks, with the same strict applier and precise errors behind each format, and re-measure whenever the model changes.
Carry it forwardFormat is a per-model choice.
Weak answerKeeping the old default because it worked before.
Now defend it
One-line choice?
Search-and-replace for existing files and whole files for new or tiny ones, applied strictly with precise errors, confirmed per model by apply rate, correctness and tokens on your own tasks.
How it's scored
Weak: Picks a format by habit without discussing failures.
Hire: Compares formats by cost and failure modes and defaults to search-and-replace with a strict applier.
Strong Hire: Adds measurement per model (apply rate, correctness, tokens), explains whole-file correctness risks, makes failures cheap with current text in errors, uses structured refactorings where they fit, guards any fuzzy matching, and re-measures on model changes.
Common mistakes
- Silent fuzzy application.
- Whole-file rewrites for large files.
- Trusting diff line numbers.
- Choosing once and never re-measuring.