Comments in code are quite often a code smell. Let’s see what is suboptimal about comments and talk about some strategies to avoid them.

  • magic_lobster_party@kbin.social
    link
    fedilink
    arrow-up
    0
    ·
    10 months ago

    Comments should be used when it’s hard to convey the intent using only code. For example, maybe there’s some unintuitive border case that must handled. Then it could be useful to add some explanation with a comment.

    I also like to add comments when I find some clever solution/workaround on the web. For example, some stack overflow answer or Wikipedia page of some algorithm.

    • Big P@feddit.uk
      link
      fedilink
      English
      arrow-up
      0
      ·
      10 months ago

      Comments are also useful when something appears to be wrong but there’s a good reason why it’s like that