craftinginterpreters icon indicating copy to clipboard operation
craftinginterpreters copied to clipboard

code block diffs instead of replaces

Open Shadlock0133 opened this issue 2 years ago • 0 comments

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.

Shadlock0133 avatar Mar 20 '23 11:03 Shadlock0133