• Feathercrown@lemmy.world
    link
    fedilink
    English
    arrow-up
    6
    ·
    1 month ago

    I spent like 3 hours yesterday deduplicating two functions that were hundreds of lines long and nearly identical. I should probably learn how to use that git command that can diff two files on disk. Luckily I actually enjoy cleaning up code sometimes.

    • pivot_root@lemmy.world
      link
      fedilink
      arrow-up
      11
      ·
      1 month ago

      If you’re using a decent development system, you’ll have an executable called diff installed already :)

    • orbitz@lemmy.ca
      link
      fedilink
      arrow-up
      4
      ·
      1 month ago

      Dunno what OS’s it supports besides Windows but I use Kdiff for random comparisons regularly, I think it works pretty well untill you get to much larger files (20+ MB slows down a lot). The huge file wasn’t code but needed to check output changes for those curious.

      I constantly check git comparison with previous versions to see what changed to break things in a build though. Didn’t know there was a way to diff any files in git,should probably just learn to use that one.

      • Ephera@lemmy.ml
        link
        fedilink
        arrow-up
        3
        ·
        1 month ago

        Git uses the diff binary under the hood (unless you configure it to use something else).
        You can invoke that directly with diff file_a.txt file_b.txt.

    • egrets@lemmy.world
      link
      fedilink
      arrow-up
      4
      arrow-down
      1
      ·
      1 month ago

      VS Code’s diff tools are killer. Comparison is smarter than most, and you can edit either file as you go.

      • wizardbeard@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        4
        ·
        1 month ago

        And if you want to avoid the Microsoft stank, there’s VS Codium that has been de-Microsoft’d, like Chrome vs. Chromium.

    • hayes_@sh.itjust.works
      link
      fedilink
      arrow-up
      2
      ·
      1 month ago

      git diff —no-index before.json after.json > showmethegoods.diff

      You don’t have to save it to a file but I often do.