munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.87k stars 1.04k forks source link

code block diffs instead of replaces #1111

Open Shadlock0133 opened 1 year ago

Shadlock0133 commented 1 year ago

It's probably wouldn't be easy to add, but having diffs instead of replaces would help with readability, as (at least for me) trying to find from surrounding lines what code to replace is difficult. E.g.

currently:

  uint8_t arg = identifierConstant(&name);

  // replaces 1 line
  if (match(TOKEN_EQUAL)) {
    expression();
    emitBytes(OP_SET_GLOBAL, arg);
  } else {
    emitBytes(OP_GET_GLOBAL, arg);
  }
}

with diff:

  uint8_t arg = identifierConstant(&name);

-  emitBytes(OP_GET_GLOBAL, arg);
+  if (match(TOKEN_EQUAL)) {
+    expression();
+    emitBytes(OP_SET_GLOBAL, arg);
+  } else {
+    emitBytes(OP_GET_GLOBAL, arg);
+  }
}

Diffs could also be split into two columns, with left being old code, and new code on the right.