• Pasta Dental@sh.itjust.works
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    12 days ago

    Am I the only one who likes to write comments when I find code that took me a while to understand even when I didn’t write the code? It helps me when I go back to that place and it helps other devs that have to do the same figuring things out as me. Idk if I’m just weird but I really like writing documentations and commenting my code

    • magic_lobster_party@fedia.io
      link
      fedilink
      arrow-up
      1
      ·
      11 days ago

      I think comments are good as a last resort when it’s difficult to communicate the intention of the code with other means.

      If I find code that’s hard to understand, I’ll first try to find better variable or function names. Often this is enough.

      If it’s still too difficult to understand, I try to restructure the code to better communicate the flow of the code.

      If that doesn’t help (or is too difficult), then I might add a comment explaining key information that’s difficult to understand from the code.