Live data from Hacker News

How far should a programming language aware diff go?

semanticdiff.com

51–54 of 54 posts

Re: How far should a programming language aware diff go?

#51
post #34

Not far. Just show all changes. Like the blog article already states, for many projects you already have code formatters, so changes in format usually don’t happen a lot - and if they do there might be a reason you don’t want to hide (like… you change your rules of code formatting). For all the other example I neither see the point why you would want to hide it. If you don’t want to see commas added in a list, make i…

The healthy workflow is: notice formatting discrepancies -> reformat -> reopen the diff, now containing only intentional, substantial changes.

Of course the edited source files should have been reformatted automatically, on save or on build, before someone opens a diff: this should never happen except as a symptom of inadequate reformatting (e.g. I decide to adopt redundant commas at the end of comma-separated lists) or abnormal operations (e.g. non-reformatted code was accidentally committed to version control).

Re: How far should a programming language aware diff go?

#52
post #35

Earlier quoted context omitted.

There is also the function scope vs block scope... var x = 3 will escape the latter.

If you mean the following, it actually doesn't: (function () { var x = 0; const foo1 = function(a, b) { var x = 2; } const foo2 = (a, b) => { var x = 3; } foo1(); console.log(x); // prints 0 foo2(); console.log(x); // prints 0 })() However, there is the difference in how the implicit semicolons are inserted: const foo1 = function(a, b) { return a + b; } (2, 3) console.log(foo1) // prints 5 const foo2 = (a, b) => { re…

> implicit semicolons are inserted

lmao what a p

Re: How far should a programming language aware diff go?

#53
post #29

There is also diffsitter. I was testing it a month ago, it works fine. Not sure what language-aware diffing exactly means, but diffsitter uses tree-sitter and it is comparing ASTs and CSTs of the files. [1] https://github.com/afnanenayet/diffsitter

Seems to be the best choice since treesitter is already generic and supports many languages. Will try this out first.

Re: How far should a programming language aware diff go?

#54
post #29

There is also diffsitter. I was testing it a month ago, it works fine. Not sure what language-aware diffing exactly means, but diffsitter uses tree-sitter and it is comparing ASTs and CSTs of the files. [1] https://github.com/afnanenayet/diffsitter

Seems to be the best choice since treesitter is already generic and supports many languages. Will try this out first.

tree-sitter is very generic and supports so many languages, it is really great. The first use case of the article, "Level 1: Irrelevant Whitespace" is covered by diffsitter.

I wanted at some point, to diff files and ignore comments for Rust source code. I wrote a small program, to remove the two different comment nodes the Rust grammar defines: line_comments and block_comments. Then i diffed the resulting uncommented code using diffsitter.

From start to finish, writing the program and testing it to many different files it took 5 hours.

Post reply on HN