this post was submitted on 20 Oct 2023
583 points (97.9% liked)

Programmer Humor

32410 readers
306 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
  • Adding a line: ✅
  • Removing a line: ✅
  • Modifying a line: ✅
  • Moving a codeblock: ❌ i see you've rewritten everything, let me just highlight it all.

RIP reviewers on my PR.

(Meme created by my coworker)

top 37 comments
sorted by: hot top controversial new old
[–] bleistift2@feddit.de 83 points 1 year ago (1 children)

I’m surprised that after almost 20 years of versioning C code, git still manages to assign the closing brace of a function wrongly.

[–] sim642@lemm.ee 8 points 1 year ago

Because text is text and all } are the same.

[–] killeronthecorner@lemmy.world 34 points 1 year ago (4 children)

I'm convinced there must be a way of using ASTs to do more intelligent diffing of a given programming language, but I'm far too lazy to find out for myself.

[–] omidmnz@lemmy.world 51 points 1 year ago (1 children)
[–] killeronthecorner@lemmy.world 24 points 1 year ago (1 children)

Hell yeah, being lazy paid off. Thanks.

[–] omidmnz@lemmy.world 7 points 1 year ago

You're welcome. And have fun trying to break it!

[–] ryathal@sh.itjust.works 11 points 1 year ago

There is, but your dif tool would have to be language aware and likely be slower to show difs.

[–] kibiz0r@midwest.social 6 points 1 year ago

There have been some attempts at semantic diffs, but it’s very uhh… difficult to gain traction with such a thing.

[–] sim642@lemm.ee 5 points 1 year ago (1 children)

Diffing algorithms on trees might not be as efficient, especially if they have to find arbitrary node moves.

[–] killeronthecorner@lemmy.world 2 points 1 year ago (1 children)

I wouldn't expect it to be, but I think modern processors can handle the load!

[–] sim642@lemm.ee 2 points 1 year ago (1 children)

It's not necessarily about the load, it's about the algorithmic complexity. Going from lists (lines in a file, characters in a line) to trees introduces a potentially exponential increase in complexity due to the number of ways the same list of elements can be organized into a tree.

Also, you're underestimating the amount of processing. It's not about pure CPU computations but RAM access or even I/O. Even existing non-semantic diff implementations are unexpectedly inadequate in terms of performance. You clearly haven't tried diffing multi-GB log files.

[–] killeronthecorner@lemmy.world 1 points 1 year ago* (last edited 1 year ago) (1 children)

Log files wouldn't fall under the banner of compiled languages or ASTs, so I'm not sure how that example applies.

And I'm aware that it can lead to O(n²) complexity but, as others have provided, there are already tools that do this, so it is within the capabilities of modern processors

Yes there will be cases where the size of the search space will make it prohibitive to run in reasonable times but this is - by merit of the existing tools and the fact that they seem to work quite well - an edge case.

[–] sim642@lemm.ee 0 points 1 year ago

Log files themselves don't, but I'm just comparing it with simpler files with simpler structure with simpler algorithms with better complexity.

[–] loganmarchione@lemmy.world 27 points 1 year ago* (last edited 1 year ago) (1 children)
[–] PeriodicallyPedantic@lemmy.ca 3 points 1 year ago

That's awesome. I wonder how it'd handle moving plus a small change.

Too bad GitHub doesn't support it yet afaict. But at least it's not all diff tools.

[–] saigot@lemmy.ca 20 points 1 year ago (1 children)

Me adding one if statement around around a code block. Ah shit I guess I own the whole function now.

[–] Rednax@lemmy.world 8 points 1 year ago

At least a good diff tool will ignore whitespace diffs.

[–] Kbin_space_program@kbin.social 18 points 1 year ago (1 children)
[–] alokir@lemmy.world 13 points 1 year ago

that's not even a joke, I'm using intellij community as a merge and diff tool exclusively. it doesn't support the language I want but even without it it's better then anything else.

[–] Blackbird@infosec.pub 11 points 1 year ago* (last edited 1 year ago)

Beyond Compare is awesome and handles this and many other things quite well.

[–] dragnucs@lemmy.ml 9 points 1 year ago (2 children)

Most diff tools have an option to ignore leading or trailing whitespace changes.

[–] Feathercrown@lemmy.world 17 points 1 year ago

Me omw to shift the entire codebase to the right by one tab and claim authorship over every line in the project with a completely untraceable commit

[–] pomodoro_longbreak@sh.itjust.works 15 points 1 year ago (1 children)

I think OP meant moving a code block up or down in a file, not left or right

[–] PeriodicallyPedantic@lemmy.ca 3 points 1 year ago

Yes, thank you. I probably should have been more clear

[–] nicoweio@lemmy.world 8 points 1 year ago* (last edited 1 year ago) (1 children)

VSCode has had that feature for some months now. Maybe it's still hidden behind an off-by-default setting, but it's there and I use it.

[–] PeriodicallyPedantic@lemmy.ca 5 points 1 year ago (1 children)

I'll have to take a look to see if I can use it to view (enterprise) GitHub PRs, because that'd be a huge help

[–] nicoweio@lemmy.world 1 points 1 year ago

Good question. Maybe GitLens can help with that, if not the official GitHub extensions.

[–] tastysnacks@programming.dev 8 points 1 year ago

If you're going to rearrange code, have that as a separate check in from changing code.

[–] dream_weasel@sh.itjust.works 7 points 1 year ago

Maybe specify a different diff algorithm? Histogram for example?

[–] csm10495@sh.itjust.works 4 points 1 year ago

Give me some love for adding an indent level either showing nothing changed or you rewrote everything too.

[–] mormegil@programming.dev 4 points 1 year ago (2 children)
[–] dill@lemmy.one 3 points 1 year ago

That logo tho. oh noooooo

[–] flux@lemmy.ml 1 points 1 year ago

It doesn't actually detect moved code, though, like git diff can? I gave it a shot and also there's a couple issues open about it, e.g. https://github.com/Wilfred/difftastic/issues/520 .

Other than that, difftastic is quite nice.

[–] MJBrune@beehaw.org 4 points 1 year ago

Perforce diff works better than this. Even my basic Git/Gitlab diffs don't do this.

[–] sim642@lemm.ee 2 points 1 year ago (1 children)

How do you expect it to be shown though?

[–] PeriodicallyPedantic@lemmy.ca 10 points 1 year ago (1 children)

For example, on side by side views, you can draw a box around it on both sides, and draw a line connecting the two

[–] Scrollone@feddit.it 3 points 1 year ago

I think Sublime Merge does this with the conflict resolution tool