OverviewDeveloperHacker

Diff Me Maybe: Build a Small Text-Diff Library from Scratch

Advanced0 enrolled · 0 submitted

Want in? Run /enroll in Discord to claim this tier before the build window closes.

The brief

Diffing is one of those things we all use daily and rarely build. Implement a compact, well-tested library that compares two texts line by line and produces a minimal edit script, then wrap it in a tiny CLI that prints a readable unified-style diff.

Your MVP: given two files, output the added and removed lines with a few lines of surrounding context.

Core outcomes:

  • Implement a real diff algorithm (Myers' O(ND) is the classic choice; a simpler LCS-based approach is fine if you document the trade-offs).
  • Expose a clean library API (e.g. diff(a, b) -> list of edits) separate from the CLI.
  • Render a unified-diff-style output with hunks and context lines.
  • Back it with a decent set of tests: identical files, empty files, all-changed, single-line change, and a randomized round-trip check (applying the edits to A must produce B).

No dependencies are needed beyond your language's standard library and a test runner. Don't worry about binary files or huge inputs; a short note in the README about limits is plenty.

Deliverables

  • A library module exposing a documented diff function, plus a CLI that prints a unified-style diff for two files
  • A test suite including a round-trip property check (apply edits to A, get B)
  • A README with a short explanation of the algorithm you chose and why, plus known limitations
  • A sample run (in the README or a recorded terminal output) comparing two real files and showing the result

Resources