• ArcaneSlime@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    21
    ·
    1 year ago

    Lmao me commenting my 14 line bash script, comments almost as long as the script itself.

    I have a habit of forgetting “why’d I put this there” and at least with my scripts I can leave myself a note for future me.

    • nuez_jr@lemm.ee
      link
      fedilink
      arrow-up
      9
      ·
      1 year ago

      The highest comment-to-code ratio I ever wrote was a CMD script that had to combine three different escaping conventions.

      It was a good day when I got to throw that one away.

    • coloredgrayscale@programming.dev
      link
      fedilink
      arrow-up
      7
      ·
      edit-2
      1 year ago

      Sounds like a good use of comments. Explain why, not how. (that should be readable from the code for the most part. Unless you’re having function calls like xmmmuldp (simd) )

    • nothacking@discuss.tchncs.de
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      This actually makes a lot of sense. A computer executing the code and a human maintaining it need to know different things. A human needs to knon what the code does on a high level (what the programmer intended), how it handles (or does not handle) edge cases, etc. A computer only needs to know how to run the code at a super low level. Without comments, it is impossible to know if code is doing the right thing, or what is expected from the caller.