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.

  • mindlessscrollingparrot@kbin.social
    link
    fedilink
    arrow-up
    7
    ·
    1 year ago

    DRY is not an inviolable rule. Some of the most tedious code to debug is because somebody thinks puppies will die if they write the same pair of lines in two different places.

    • danrot@kbin.socialOP
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      I think this is one of the most common misconceptions about DRY. Just because you have two times the same line in your code base it is not automatically a violation of DRY. If you compare if a number is bigger than 18 it is definitely not a good idea to extract that part if you are comparing the hour of the day once and the age the other time. In that case it would even be bad to create an abstration, and it would not be a violation of DRY. And I agree that something like this leads to code that is hard to maintain.