# Read a code diff for behavior, not just changed lines

> Use a small default-value change to review a diff, separate whitespace noise and choose examples that expose changed behavior.

- Canonical HTML: [https://unrust.dev/blog/review-a-code-diff-with-intent](https://unrust.dev/blog/review-a-code-diff-with-intent)
- Markdown representation: [https://unrust.dev/blog/review-a-code-diff-with-intent/index.md](https://unrust.dev/blog/review-a-code-diff-with-intent/index.md)

Published: 2026-10-16. By the Unrust team.

[Open the companion tool](https://unrust.dev/tools/text-diff/index.md)

## Write the intended behavior before reading the colors

Suppose a retry setting allows zero to mean “do not retry.” An omitted value should use three retries. That one-sentence contract gives you a way to judge the change below. Without it, the two lines can look like interchangeable ways to write a default.

Paste the original function into Before and the revised function into After in the diff checker. You should see one removed line and one added line. Read both in the surrounding function, then explain the behavioral difference in your own words.

```javascript
// Before
function retries(value) {
  return value || 3;
}

// After
function retries(value) {
  return value ?? 3;
}
```

## Choose inputs that distinguish the versions

A positive value such as 5 produces the same result in both versions. It is a poor example for deciding whether this change matters. Try 0 instead: logical OR returns 3, while nullish coalescing preserves 0. For the stated contract, preserving zero is the behavior you want.

Also consider undefined, null, false, an empty string and NaN. Some of those may be invalid inputs for a retry count. The defaulting expression alone does not establish that the result is a valid nonnegative integer. A reviewer should ask where validation happens rather than assuming that changing the operator completes the feature.

## Reduce whitespace noise deliberately

The checker compares lines and shows the original line numbers. It normalizes CRLF and CR line endings to LF, and it always tells you whether the final newline differs. Enable Ignore trailing spaces and tabs only when that choice matches the question you are reviewing. Unchanged rows then display the after text.

Do not assume whitespace is harmless everywhere. Indentation can carry meaning in Python, and spaces inside string literals can be data. This option ignores only spaces and tabs at the end of a line; it does not ignore indentation or all internal whitespace. If whitespace itself matters, leave the option off and inspect the original inputs.

## A line comparison is evidence, not an explanation

A moved block can appear as removed and added lines. Repeated lines can admit more than one sensible alignment. The tool chooses a deterministic line alignment; it does not understand control flow, rename symbols or establish whether two programs are equivalent. Use the comparison to locate the edit, then reason about what runs.

For the retry example, inspect the caller and the code that uses the count. If a zero limit causes another function to loop forever, preserving zero exposes a second problem. The visible edit is small, but the behavior contract crosses a function boundary. Keep the review proportional to that effect.

## Save the reasoning with the change

The comparison report includes added and removed markers, line numbers, the whitespace setting and final-newline state. It is readable evidence for a discussion, not a patch that can be applied with Git. For repository changes, use your normal Git diff alongside tests and the surrounding source.

A useful review note can be short: “Zero disables retries; this preserves zero. Undefined still defaults to three. Invalid negative and fractional inputs are checked by the caller.” Only make the last claim after verifying it. The goal is a change whose intended behavior another developer can assess, not just a page of green and red lines.

## References and next steps

[Git: diff output and whitespace options](https://git-scm.com/docs/git-diff)
[MDN: nullish coalescing](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)

[Review code with a clear behavior contract](https://unrust.dev/guides/reading-code-against-a-contract/index.md)

[Take the free diagnostic without tools or hints](https://unrust.dev/diagnostic/index.md)
