Loading video player…

Look Beyond the Diff

In this lesson, you watched a review look past a diff. The change was made up for the video, on a local branch, so it isn’t in your clone. It renames the saved order field refunded to refundedPence, so the name says the unit.

Key Points

  • Every line in the diff was right. Four files changed, each hunk swapped the old name for the new one, and npm test passed 15 of 15. However, a diff shows the lines that changed, with a few lines around them. Code elsewhere that still uses the old name isn’t in it.
  • The principle: a change reaches past its own lines, so look for every reader of what it touches.
  • Search the whole repo for the old name on an order. With -w, git grep matches whole words only, so refundedPence doesn’t count. Three lines came back. The one in createRefund() is an event’s name, in quotes, so it’s text and doesn’t read the field. The other two are outside the diff. weeklySales() in src/reports/weekly.js builds the report’s refunded and net columns from the old field. The orders table in the staff desk, the admin page you’ve used (public/admin/app.js), shows it too.
  • Search the field’s bare name and the callers too. Also search the field’s bare name, refunded, and the changed functions’ callers, and check each hit outside the diff.
  • Ask of each reader: does this still get what it expects? An order placed on the branch has no refunded field, so where both expect a number of pence, they read undefined.
  • Search the data too. Saved data can hold the old name. A search of the data/ folder for the old name finds one line in the seed file, data/seed.json: order-1, Nadia’s order, with "refunded": 0. The diff left this file alone, yet npm run seed copies it into the shop’s data, and the tests load it too. So every seed gives order-1 the old shape, with no refundedPence. A live shop’s orders saved before the change would keep it too. So createRefund() and updateStatus(), the diff’s own functions, read a field order-1 doesn’t have.
  • Run the branch to check what you read. A new order for Nadia in the staff desk, order-2, is in the new shape. Its row shows £NaN returned. The table reads the old field, so it gets undefined. Arithmetic on undefined gives NaN, short for not a number. The weekly report shows NaN for order-2 too.
  • Then a return on order-1, the order in the old shape. On main, that row shows £4.50 returned and the status partly-refunded. £4.50 is short because of main’s own refund bug, the one you found with git bisect, and it’s the same on both branches. On the branch, the return is saved, yet order-1’s row shows £0.00 returned and the status is still paid. The return had no refundedPence to add to, and the table still reads the old zero.
  • Write down the affected places, next to your review: the weekly report, the orders table, the seed file, and orders already saved. Give each its evidence: the line you found, or the run. Note what you checked and found not affected too, such as the event name.
  • The rule: for each name or saved shape a change touches, search for every reader, including the data already saved, then run the branch to check.

The Searches

These are the commands the video ran, on the made-up branch:

Language: Shell
$ git switch made-up/refunded-pence
$ git show --stat --format='%h %s' HEAD
$ npm test
$ git grep -n -w -F "order.refunded"
$ git grep -n -w -F "refunded" data/
$ npm run seed
$ npm start
$ npm run weekly-report

A full review also searches the field’s bare name and the changed functions’ callers, then checks each hit outside the diff:

Language: Shell
$ git grep -n -w refunded

The search for readers of the old name on an order found these three lines:

Language: Text
public/admin/app.js:34:        appendText(row, 'td', pounds(order.refunded));
src/refunds/create.js:41:    eventLog(state, 'order.refunded', { ... });
src/reports/weekly.js:8:  ... paid: order.total, refunded: order.refunded, ...

The search of the data folder found this one:

Language: Text
data/seed.json:33:    "code": "READ20", "total": 2400, "refunded": 0, "status": "paid",

The List of Affected Places

This is the list written next to the review:

Language: Text
Reaches · made-up/refunded-pence
1. src/reports/weekly.js:8 · run: order-2 NaN in the report
2. public/admin/app.js:34 · run: order-2 shows £NaN
3. data/seed.json:33 · seed and tests load order-1 with refunded
4. orders saved before the change · run: order-1's return shows £0.00, still paid
Checked, not affected: src/refunds/create.js:41, the event name (text)

After a real review, switch back to main, seed again, and delete the branch, so the working tree is clean.

Next, in Exercise: Find What the Change Reaches, you’ll read a small change to part of the shop and list every place it reaches.

00:00 In Read a Change in Order, you read a change from its description to its last hunk. This change is made up for this video, on a local branch, so it isn’t in your clone.

00:10 Watch rather than follow along. It renames a field on every saved order, from refunded to refunded pence, so the name says the unit. The file list shows four files.

00:22 Each hunk swaps the old name for the new one, and each line is right. The tests pass, all fifteen. So can you approve it? Watch out: a diff shows the lines that changed, with a few lines around them.

00:37 Code elsewhere that still uses the old name isn’t in it. Here’s the principle: a change reaches past its own lines, so look for every reader of what it touches.

00:50 The change touches one field, so search the whole repo for the old name on an order. Also search the field’s bare name, refunded, and the changed functions’ callers, and check each hit outside the diff.

01:02 With -w, git grep matches whole words only, so refunded pence doesn’t count.

01:09 Three lines come back. The one in createRefund() is an event’s name, in quotes. It’s text, not the field.

01:17 The other two are outside the diff. weeklySales() builds the report’s refunded and net columns from the old field. The orders table in the staff desk, the admin page you’ve used, shows it too.

01:30 For each one, ask: does this still get what it expects? An order placed on this branch has no field called refunded. So where both expect a number of pence, they’d read undefined.

01:44 Saved data can hold the old name. Search the data folder for the old name. One line comes back, from the seed file: order-1, Nadia’s order, with refunded at zero.

01:57 The diff left this file alone. Yet npm run seed copies it into the shop’s data, and the tests load it too. So every seed gives order-1 the old shape, with no refunded pence.

02:09 A live shop’s orders saved before the change would keep it too. So the diff’s own functions, createRefund() and updateStatus(), would read a field order-1 doesn’t have.

02:20 Every line in them is right, but only for new orders.

02:26 All that came from reading. Now the branch runs. First, a new order for Nadia in the staff desk, so there’s an order in the new shape: order-2. Its row shows NaN pounds returned.

02:39 The table reads the old field, so it gets undefined. Arithmetic on undefined gives NaN, short for not a number. The weekly report shows NaN for order-2 too.

02:51 Next, a return on order-1, the order in the old shape. On main, that row would show four pounds fifty returned, and partly refunded. Four pounds fifty is short, but that’s main’s own refund bug, the one you found with git bisect, not this change.

03:08 On this branch, the return is saved. Yet order-1’s row shows nothing returned, and it’s still paid. The return had no refunded pence to add to, and the table still reads the old zero.

03:21 Every hunk was right, and the tests passed. The shop still went wrong outside those four files.

03:29 Next to your review, write the list of affected places: the weekly report, the orders table, the seed file, and orders already saved. Give each its evidence: the line you found, or the run.

03:42 Note the event name as checked, not affected. After a real review, switch back to main, seed again, and delete the branch, so the working tree is clean.

03:54 Here’s the rule: for each name or saved shape a change touches, search for every reader, including the data already saved, then run the branch to check.

04:06 Next, in Exercise: Find What the Change Reaches, you’ll read a small change to part of the shop and list every place it reaches.

Become a Member to join the conversation.