Is there a good reason why diff tools generally don’t use AST?
Performances is one I guess.
Difftastic: A diff that understands syntax
11–20 of 224 posts
Re: Difftastic: A diff that understands syntax
#12Is there a good reason why diff tools generally don’t use AST?
Finally, even if you have a syntax tree, that is just part of the solution, probably the smaller one. Detecting three lines of code wrapped in a new if statement is easy but also doesn't benefit much from a syntax-aware algorithm. But once you changes names and signatures, extract methods, introduce constants, and so on it will become progressively harder to match subtrees and one is probably quickly approaching the territory of NP-hard and undecidable problems.
Re: Difftastic: A diff that understands syntax
#13This looks absolutely amazing. One thing I do find interesting (and a wish were different) is that only programming languages are supported, rather than data formats as well. For example, two JSON documents may be valid but formatted slightly differently, or a common task for me is comparing two YAML files. Comparing config files that have a well defined syntax and or can be abstracted into a tree (JSON, YAML, TOML,…
JSON is supported. HTML and XML are missing, too.
Sadly YAML, TOML and the others I mentioned are not there (yet?)
Re: Difftastic: A diff that understands syntax
#14I would recommend putting an installation guide in your readme, and it being a full installation guide.
I followed the link to your manual and then it told me to install your tool using a tool called "cargo" with no reference on how to install cargo. At this point I gave up. Lazy, maybe, but for a convenience tool like this I want a convenient installation.
Re: Difftastic: A diff that understands syntax
#15Re: Difftastic: A diff that understands syntax
#16I paid and used SemanticMerge quite successfully when we had a complex Git workflow with lots of conflicts. https://semanticmerge.com/ Since moving to short lived feature branches it is less useful to me.
Re: Difftastic: A diff that understands syntax
#17Looks really cool, but there was no instructions on how to install it. I would recommend putting an installation guide in your readme, and it being a full installation guide. I followed the link to your manual and then it told me to install your tool using a tool called "cargo" with no reference on how to install cargo. At this point I gave up. Lazy, maybe, but for a convenience tool like this I want a convenient ins…
Re: Difftastic: A diff that understands syntax
#18Is there a good reason why diff tools generally don’t use AST?
Because it is much easier, you don't have to build and maintain parsers for hundreds of languages. And you don't need need just any parser, you need very robust ones that can deal with malformed files well. Or, if you only pick a small set of supported languages, your diff tool will not work on most files or have to fall back to a structure-agnostic algorithm. Also not all text files even follow any useful grammar at…
I've thought before this is how diffing should be done, and speculated that tree-sitter would make it more feasible.
At this point, whenever I think some language-aware tool ought to exist, my first thought is "Does the language server protocol or tree-sitter make this more feasible?"
Re: Difftastic: A diff that understands syntax
#19If you have consistent code style and formatting this tool is unnecessary. I think that solution is better, you get a more consistent code base that is easier to read for humans. (Also diffs will be faster to compute)
Re: Difftastic: A diff that understands syntax
#20If you have consistent code style and formatting this tool is unnecessary. I think that solution is better, you get a more consistent code base that is easier to read for humans. (Also diffs will be faster to compute)
I disagree. I struggle to replicate it right now using a simple test, but I've seen the following rather infuriating and counter intuitive behaviour from Git/GNU diff. If you have a simple if statement such as:
if (bla) {
// do something
}
And you were to add another statement at the end, after the closing curly brace, e.g.: if (bla) {
// do something
}
if (bla2) {
// do something else
}
Git/GNU diff will sometimes show the following diff: diff --git 1/left 2/right
index c2ea6f1..dc0e1c2 100644
--- 1/left
+++ 2/right
@@ -1,3 +1,6 @@
if (bla) {
// do something
+}
+if (bla2) {
+ // do something else
}
This is basic example, but there's other similar things. For a simple change like the above, this isn't a huge issue, but for a bigger patch sets, it can take a minute to understand what is really going on.