Live data from Hacker News

Difftastic: Syntax-aware structured diff tool

github.com

21–30 of 62 posts

Re: Difftastic: Syntax-aware structured diff tool

#22

My favorite diff tool is the one shipped with Plastic SCM, Xdiff. Since it's visual, it makes it very easy to see what changes have been done to the file. https://www.plasticscm.com/features/xmerge

And theirs Git UI, gmaster, includes the same diff tech too. I do not use it for everyday tasks, but when I need to understand complex and/or big changes this is my go-to tool.

Re: Difftastic: Syntax-aware structured diff tool

#24
This is cool. I work with a large Python codebase that's been around for a while (hasn't been that long since it's been completely off Python 2). It's not a bad codebase, but naturally it has almost no typing annotations, and other devs are just starting to come around to the idea.

I love `mypy --strict` but it produces way too much noise with all the other code, so I've been using a tool I made that runs mypy over the changed files and then greps the output to filter for lines that `git diff` points out have changed. It's pretty rough and imperfect (doesn't catch errors that started appearing in unchanged files, or unchanged lines it the same file, for instance) but it's still quite helpful. I've been meaning to make an improved version that runs mypy over the branch point, then over my branch, and then maps new and changed lines between them so it displays all errors that are new, but I haven't gotten around to it yet. It'd be useful for other tools too, like semgrep.

Re: Difftastic: Syntax-aware structured diff tool

#25

To ease the pain in conventional differs, we use a pre-commit hook to format the source code (prettier). This way we only see differences if something _actually_ changed.

This worsens the problem especially in templates when the nesting changes.

Good diff tools will only show you that the indentation changed, not the line as a whole (Meld for example).

Re: Difftastic: Syntax-aware structured diff tool

#26

This is cool. I work with a large Python codebase that's been around for a while (hasn't been that long since it's been completely off Python 2). It's not a bad codebase, but naturally it has almost no typing annotations, and other devs are just starting to come around to the idea. I love `mypy --strict` but it produces way too much noise with all the other code, so I've been using a tool I made that runs mypy over t…

This sounds well in line with what I have been building - a tool to take syntax-aware diffs across git commits: https://github.com/bugout-dev/locust

It currently supports Python, Javascript, and Java. I like the idea of mypy changes, as well.

Re: Difftastic: Syntax-aware structured diff tool

#27
post #9

To ease the pain in conventional differs, we use a pre-commit hook to format the source code (prettier). This way we only see differences if something _actually_ changed.

I think code formatting should be mandatory and one of the first things you adopt in your project. Resist code style rule changes as much as possible, and if you do, apply them across the whole codebase in one go to avoid churn and noise in diffs down the line. And if you do make style changes, put them in a separate commit at the very least so the diffs are cleaner and code reviews are easier. In my project I use go…

And if you do decide to do single-commit massive style changes, add the commits to an ignore revs file: http://git-scm.com/docs/git-config#Documentation/git-config....

Re: Difftastic: Syntax-aware structured diff tool

#28
I built a diff tool for spreadsheets years ago: https://support.smartbear.com/collaborator/docs/working-with...

Never really worked all that well. I looked for research on how to diff something like that but didn't find anything useful. IIRC the diff works by "serializing" the cell grid, effectively treating each cell as a separate "line" and then running that through a conventional line-based diff algorithm.

Re: Difftastic: Syntax-aware structured diff tool

#29
That is a really difficult problem for more reasons than what fits in this comment :) In fact, I got my PhD studying this very problem (https://victorcmiraldo.github.io/data/MiraldoPhD.pdf).

I did not find any description of how your diffing algorithm works nor how you represent a patch. I'd be really curious to know more.

Re: Difftastic: Syntax-aware structured diff tool

#30

I wrote diffr [0] for that purpose; it serves me well, especially if your team makes code with long lines. In my opinion, a simple approach that does NOT make any parsing is more efficient (what about bugs in your parser? code with syntax errors? also, how fast would the parser be?) [0]: https://github.com/mookid/diffr

Many of your concerns could be alleviated by using Tree-Sitter. (https://tree-sitter.github.io/tree-sitter/)
Post reply on HN