Live data from Hacker News

How far should a programming language aware diff go?

semanticdiff.com

21–30 of 54 posts

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

#21
post #15

I think I have heard of their product before, and reading the blog post intrigued me, so I wanted to try it, but... VS Code Integration? GitHub Integration? No standalone version which you could actually use as a diff tool for git locally? Ok, I guess only having a "cloud" version makes licensing easier, and you can call me old fashioned, but seeing an eminently "offline" task such as diff being turned into "online-o…

The VS Code extension works offline. The diff calculation is performed on the host where the VS Code GUI is running (makes a difference in case of SSH/Docker/WSL).

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

#22
It's a very interesting question. One idea I've toyed with over the years is a language specifically designed to facilitate effective diffs.

Anyway, it seems the "Level 3: semantic diff" actually could be divided into different levels. But "Level 4: Mostly identical" seems quite problematic.

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

#23
I think the general answer is, it depends.

Hopefully this tool gives a dev ready control of what kinds of differences to hide/show.

I'm actually not convinced of the concept of semantic diff (not talking just about this tool specifically)... when we talk about code that is different but equivalent, I think we're talking about elements of style.

It seems to me that it would pretty much always be better to normalize the elements of style considered insignificant, rather than hide them just in the diff tool. That covers diffing as well as viewing/reading the code.

If you don't care about a particular element of style then either it shouldn't be coming up much or I think you'd be better off using some kind of enforcing/fixing linter.

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

#24
In theory semantic diff is useful, but based on my code review experience, it hardly matters. For a language like Python or JavaScript, a developer fluent in these languages don't really pay much attention to these things anyway, just like you don't normally pay much attention to commas and periods in a sentence unless it causes confusion. Personally I wouldn't pay $5/month out of the pocket for this functionality.

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

#25
I think I'd appreciate some sort of "semantic grouping" of individual changes more than drawing someone random line and classifying all changes below it as "trivial".

The problem is that even a lot of the changes that normally constitute clutter can become relevant in certain situations or even introduce bugs.

One example would be ordering of Python imports: Changing the order of imports should have no effect on program behaviour if all your packages are well-behaved - and in 99.99% of cases it indeed hasn't. But the fact remains that imports are statements that are executed and can have side-effects. If a package does something nontrivial during load, changing the import order can have effects. Hiding such a change could mask introduction of a bug.

Hiding changes can also lead to confusion if you are trying to understand a series of changes that are based on each other, or if all changes of a commit are hidden. I've had the latter situation with IntelliJ, where the working tree was shown as "unclean" but the diff was completely empty. Solution: The diff wasn't actually empty, IntelliJ was just set to hide the changes.

I think a more interesting solution would be to build a sort of "tree of changes": At the bottom, you'd have the individual changes in the file; one level up, the changes would be grouped into higher-level operations, such as "change formatting", "rename identifier", "remove field", "move function", etc. If possible, those could be grouped into even higher-level changes, such as "implement new class" or "extract expression into function", etc.

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

#28

After switching to difftastic for semantic diff, I have never looked back. ( https://github.com/Wilfred/difftastic ) How does semanticdiff compare to that? Anyone got experience?

You can find a comparison of the two tools here: https://semanticdiff.com/blog/semanticdiff-vs-difftastic/

As author of SemanticDiff, I am obviously a bit biased. But Wilfred, the author of difftastic, found the analysis to be "pretty even-handed" [1], so I think it should be somewhat fair.

[1]: https://x.com/_wilfredh/status/1764424652611318146

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

#30
post #20

Earlier quoted context omitted.

My guess would be that quite a large portion of changes we'd expect at a glance to be identical aren't, especially for inputs that would not be expected. I'd also guess this is much more likely in languages in which valid code commonly produces undefined behavior. If the tool could show you, for example, "this change is functionally identical except for when the sum of the two inputs overflows a UInt64", that'd be pr…

That would neat, although I suspect most compilers/linters should already be able to warn you about potential overflows. If you want to boil down what devs are looking for in a diff tool to one thing, it would be "which change(s) between these two versions of code result in a different binary (or AST/opcodes/bytecode, depending on the language)?" All other changes, while certainly sometimes useful to know about, are…

Literally every time you add/subtract/multiply two variables there is a potential overflow. In relatively rare cases, the compiler might be able to prove that they can't overflow, but in the general case it can't, and I doubt any actually do.
Post reply on HN