Summary (AI generated)

Archived original version »

Difftastic is a structural diff tool designed to improve code comparison by understanding syntax rather than relying on line-based differences. Traditional diffs often fail with reformatted or nested code (e.g., Lisp parentheses), but Difftastic uses an algorithm rooted in graph theory, treating each position pair in the two files as nodes connected by edges weighted based on edits (unchanged, added, removed). This minimizes structural changes rather than text lines.

To handle nested lists (like JSON or XML), it tracks parent list entries to synchronize their exits, preventing exponential state growth. A pragmatic limit of two vertices per position pair ensures manageable computation while still yielding accurate results. The UI aligns code without relying on common lines, using a two-column display even for entirely restructured files.

The tool prioritizes user-friendly outputs by adjusting edge costs and post-processing diffs to favor intuitive edits over strictly minimal ones (e.g., avoiding unnecessary splits of parentheses). However, challenges remain, such as handling large string literals or cases where minimal changes highlight trivial differences. Future work includes refining these areas and exploring word-level diffs for strings.

Despite its complexity, Difftastic consistently delivers clear results, especially with structured data. It’s open-source (MIT-licensed), aiming to inspire better diff tools that respect code semantics over text syntax. While not perfect, it addresses longstanding limitations of line-based diffs, making code changes more intuitive and easier to review.