• buzziebee@lemmy.world
    link
    fedilink
    arrow-up
    13
    ·
    edit-2
    1 year ago

    Yeah "why" comments are absolutely fine, "what" comments are useless at best and can be harmful at worst.

    I feel like this constant flood of "write comments" posts are from CS students who are told to comment everything by their lecturers. Descriptive variable and function names help explain the "what" of code pretty well most of the time.

    Sure with some old languages like C89 where you are limited in your variable name length you probably do need comments to explain wtf is going on, but most code bases aren't as constrained.

    • _stranger_@lemmy.world
      link
      fedilink
      arrow-up
      9
      ·
      edit-2
      1 year ago

      I have this argument with other devs all the time.

      Hey, you know this 200 line nested if statement that suddenly returns in the middle of the condition is "7"? Yeah, that needs a refactor or at least a fucking comment.

      I get a pull request that adds a log line that reads something like "special case 7 triggered.".