What should semantic diffs highlight: The change or its effect?
-
[email protected]replied to [email protected] last edited by
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]replied to [email protected] last edited by
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]replied to [email protected] last edited by
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]replied to [email protected] last edited by
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.
-
[email protected]replied to [email protected] last edited by
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]replied to [email protected] last edited by
it allows string interpolation with the syntax in the photo
-
[email protected]replied to [email protected] last edited by
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 sring 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.
-
[email protected]replied to [email protected] last edited by
Options 1 and 3 make sense to me.
Option 2 feels like something specific:
Similar to cases like100
vs100U
with the second one denoting "unsigned". -
[email protected]replied to [email protected] last edited by
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]replied to [email protected] last edited by
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.