2025-10-17

vak: (Default)
Вот как я нынче пишу код, посредством Курсора.

Даю задание:
Please enhance TestPDP7CompilerB in file examples_test.go. On mismatch, instead of printing the whole output (it's huge), show line by line diff using library `sergi/go-diff`.
Он задаёт уточняющие вопросы:
I scanned examples_test.go and go.mod. TestPDP7CompilerB currently prints the entire outputs on mismatch, and sergi/go-diff isn’t a dependency yet.
Do you want the diff to show only changed lines or include context lines (e.g., 2)?
a) Only changed lines
b) Include 2 lines of context
Should we cap the number of diff lines printed to avoid spam?
a) No cap
b) Cap at 500 lines
Уточняю:
Include 2 lines of context. Cap at 100 lines.

Через минуту готов план:
Add sergi/go-diff to go.mod and tidy
Implement buildLineDiff helper using diffmatchpatch
Use the helper in TestPDP7CompilerB and adjust imports
Run tests to verify improved diff output and cap behavior
Одобряю план, жму кнопку Build. Через две минуты решение готово. Проверяю - действительно, показывает приемлемый дифф. Коммичу в git для сохранности. Но решение выходит ценой лишних 120 строчек кода. Больно громоздко. Хорошо, попробуем другой вариант. Даю новой задание:
Looks complicated. Please replace that library with kylelemons/godebug/diff for simplicity.
Через полминуты имеем новый план:
Remove sergi/go-diff from imports and go.mod
Add github.com/kylelemons/godebug to go.mod and tidy
Reimplement buildLineDiff using godebug/diff and cap output
Run tests and validate new diff format and limits
Курсор просит разрешения сходить на сайт разработчика библиотеки, уточнить документацию. Ради бога, какие проблемы. Через пару минут получаю гораздо более простой код. Задача выполнена.