Live data from Hacker News

Difftastic: Syntax-aware structured diff tool

github.com

1–10 of 62 posts

Re: Difftastic: Syntax-aware structured diff tool

#4
Been hoping for more of this for years. We stare at diffs all day yet we have to accommodate the computer by understanding that the parenthesis it claims was changed wasn’t actually changed, there was just another set of parentheses added. There’s of course limits to how much a diff tool can extract meaning from two pieces of content, but structure and perhaps even heuristics like “new function was added here, maybe the curly brace belongs with that and not the old function” would certainly help.

Re: Difftastic: Syntax-aware structured diff tool

#5

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.

Prettier works for JS.

A similar Python tool is Black: https://github.com/psf/black

> Black makes code review faster by producing the smallest diffs possible.

Re: Difftastic: Syntax-aware structured diff tool

#6
I worked on this problem for just over a decade before moving onto other things. It’s a tough problem to solve.

The biggest problem I ran into is that the largest segment of user growth were too fickle. They wanted all kinds of magic in new optional features for their personal preferences that took incredible effort. I lacked the analytics to see who used which exotic features. Most of these people just wanted a beautifier more that a diff tool and would drop you in a heartbeat for more popular tools that wouldn’t do what they wanted but were popular.

The tool I wrote did have a strong following mostly around markup language parsing that was not at all exotic but solved problems other tools refused to approach.

My guidance is don’t become a code beautifier. In the languages I was supporting during the time frame I was supporting this code beautifiers were all the rage. Nobody seemed to want a diff tool with extra capabilities. Stick to being a diff tool. The people that are intentionally looking for intelligent diff tools tend to be more engineering focused and make for a loyal audience. People looking for code vanity are just the same as window shoppers walking down a street.

Re: Difftastic: Syntax-aware structured diff tool

#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 gofmt (goimports) for back-end code and prettier for front-end; I've configured my editor to apply those on save, and a pre-commit hook to either run the formatter, or error if the formatting is not according to the spec.

One of Go's proverbs is "Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.". Consistency and low noise is more important (in that case) than a specific code style preference.

Post reply on HN