craftinginterpreters
craftinginterpreters copied to clipboard
code block diffs instead of replaces
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.