this post was submitted on 04 Feb 2025
37 points (97.4% liked)

Programming

18101 readers
155 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
top 19 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 4 hours ago

this is neat but also is a closed source extension. I use https://github.com/Wilfred/difftastic which doesn't do quite as much and doesn't integrate outside of git's diff, but is still significantly better than nothing

[–] [email protected] 23 points 3 days ago* (last edited 3 days ago) (1 children)

"" to '' … There is nothing to highlight for SemanticDiff.

Really? I definitely want to see that. I want to be deliberate about my code. I am not only targeting compiled code. I am also targeting developers through maintainable code.


I'm surprised they did not list an alternative that would be my preference: Highlight the entire string. The f prefix changes the entire text value type. I would like the `f´ to be highlighted strongly, and string it changes the interpretation of weakly, and the placeholder variable more strongly again.

[–] [email protected] 5 points 3 days ago (3 children)

Many code formatters decide whether to use " or ' based on some configuration and whether the default one would require escaping. So if you are using such a code formatter, this is no longer a deliberate choice unless you explicitly override the behavior with annotations.

I am not sure whether your solution of using a less intense color for the unchanged part of the string would make it clearer. It is just more similar to other diff tools that highlight the whole line with a less intense color if it contains changes.

[–] [email protected] 4 points 2 days ago (1 children)

Then with a code formatter you definitely want to show this change. In a normal usage the code formatter should ensure that this kind of diff can't happen, then it's useful to see if it was not used during a code review.

[–] [email protected] 2 points 5 hours ago (1 children)

just stick a verification task in ci. if I have to check if the format matches the standard in a code review instead of reviewing meaningful things my time is being wasted

[–] [email protected] 1 points 2 hours ago

Yeah exactly, I'm not it was clear that it was what I meant by "the formatter should ensure ..."

[–] [email protected] 2 points 2 days ago* (last edited 2 days ago)

would make it clearer

Would make what clearer?

If I change a string to a raw string or an interpolated string, it is a semantic change on the entire string, even if it leads to consequential changes only on subsections of it. The next time or additional changes I make must take different semantics into account.

[–] [email protected] 1 points 2 days ago

If the formatting configuration forces one specific style then that is the deliberate choice; to have that one.

If there is no uniform single string quoting it is useful to differentiate between them; for example if for normal strings ' is preferred while for specific cases where escaping characters like \n is required, " must be used.

[–] [email protected] 4 points 2 days ago

I like the way azure dev-ops do it, they highlight the entire line with a soft color and the changes with a harder one. Isn't not semantic afaik.

[–] [email protected] 4 points 2 days ago* (last edited 2 days ago) (1 children)

The most obvious option: highlight what changed, the whole string. If you changed the string from interpolated to non-interpolated, the meaning of the whole string changed; it is no longer a method to concatenate variables, it has become a literal string.

Same for the example of single to double quotes. In some languages, double quotes are only used in specific contexts, so its use changes the meaning of the code. The post seems to dismiss this fact too easily.

[–] [email protected] 3 points 1 day ago* (last edited 1 day ago) (1 children)

The post chooses to use Python, where single and double quotes are equivalent and are not a semantic change. In other languages that might be, but that's not the point of the article. A semantic diff is language dependent.

[–] [email protected] 1 points 23 hours ago (1 children)

Just because they are equivalent for the labguage does not mean they are interchangeable. I may choose to use single or double quotes in specific cases and need that change to be visible, even if the language rules say it is indifferent.

This is the obvious one: The way the string is written changes, but its content remains the same. There is nothing to highlight for SemanticDiff.

Moreover, my point was about how they phrase it. It seems they dismiss what the code means to developer by mentioning "content" and discarding "the way the string is written".

[–] [email protected] 1 points 23 hours ago

I may choose to use single or double quotes in specific cases and need that change to be visible, even if the language rules say it is indifferent

Then a semantic diff is not for you, just use the old method.

[–] [email protected] 4 points 3 days ago* (last edited 2 days ago) (1 children)

I don't see what's the point of the second one if the syntax highlight, even in the first example, already shows a changed role.

A more realistic solution for the example code would be to setup a linter in the pipeline, and if one letter variables and/or template literals are detected, depending on how nice you are, reject the commit, or send an email requesting the author to be beaten up with a crowbar to the teamlead, and a copy, parsed by chatGPT for formality and politeness, to the HR.

[–] [email protected] 2 points 4 hours ago

that's not a one letter template literal, that's built in python syntax. it only has combinations of u r and f and no user defined option. f makes it templated

[–] [email protected] 1 points 2 days ago (1 children)

I don't speak python. Does the f in the top example affect string interpolation or something? If the above replaces {bar} and the below does not, highlight all after the equals sign would be my preference.

[–] [email protected] 7 points 2 days ago

it allows string interpolation with the syntax in the photo

[–] [email protected] 0 points 2 days ago

Options 1 and 3 make sense to me.
Option 2 feels like something specific:
Similar to cases like 100 vs 100U with the second one denoting "unsigned".

[–] [email protected] 1 points 3 days ago

This is an interesting problem to mull over; thanks for posting it!