• @ArcaneSlime@lemmy.dbzer0.com
    link
    fedilink
    2111 months 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
      cake
      link
      fedilink
      1011 months 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
      7
      edit-2
      11 months 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) )

    • haruki
      link
      fedilink
      611 months ago

      Well, bash scripts are infamous for being arcane so commenting abundantly is better than nothing.

    • @nothacking@discuss.tchncs.de
      link
      fedilink
      311 months 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.