• 1hitsong@lemmy.ml
    link
    fedilink
    arrow-up
    25
    ·
    1 个月前

    I’ve been rallying against clever code for years!

    Sure, it makes you have less lines for your l33t code solutions, but in the real world, it sacrifices the maintainability of code that others will eventually work on.

    Between a clever 1 line fix and maintainable 10 line fix, I’ll choose the 10 line every time.

    • curbstickle@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      10
      arrow-down
      1
      ·
      1 个月前

      As an extensive commenter, I completely agree.

      I need to know wtf I was doing, making it convoluted to save a few lines is pointless.

        • curbstickle@lemmy.dbzer0.com
          link
          fedilink
          arrow-up
          8
          arrow-down
          4
          ·
          30 天前

          “Some people do a bad job commenting and updating comments, so lets not do comments” is not an approach that works for me.

          Most of my code is at the prototype level. I’m concepting something out, usually paired with hardware.

          If someone can’t follow what I’m doing, its going to lead to problems. If a change happens to the hardware being controlled, code will not be good enough on its own.

          Rather than being accepting of bad commenting practice, make comments (and updating them properly) part of good practice. In my experience, It saves time in the long run and leads to better code at the end.

          • pcouy@lemmy.pierre-couy.frOP
            link
            fedilink
            arrow-up
            9
            ·
            29 天前

            That’s not what I said. I said that comments can often (but not always) be replaced with good and explicit names.

            This can be pushed to some extreme by making functions that only get called at a single place in the code, just for the sake of being able to give a name to the code that’s inside (instead of inlining it and adding a comment that conveys the same informations as the function’s signature)

            It’s definetly not for everyone, but for beginners/juniors it gives something objective they can aim for when trying to build good coding habits

            • curbstickle@lemmy.dbzer0.com
              link
              fedilink
              arrow-up
              6
              arrow-down
              1
              ·
              edit-2
              29 天前

              I am going to disagree, comments should be an explanation.

              The code is what’s being done, a comment should be why its being done.

              • pcouy@lemmy.pierre-couy.frOP
                link
                fedilink
                arrow-up
                6
                ·
                edit-2
                29 天前

                I’m not sure how we disagree. At least, I don’t disagree with you. My whole comment was talking about “what” comments. “Why” comments are a very good thing to have where they’re needed

                • curbstickle@lemmy.dbzer0.com
                  link
                  fedilink
                  arrow-up
                  2
                  arrow-down
                  3
                  ·
                  29 天前

                  Not updating comments with code is what I’m talking about - that’s not a comment problem, thats a programmer problem.

                  If they aren’t updating the “why”, that programmer is the problem, not comments.

    • MonkderVierte@lemmy.ml
      link
      fedilink
      arrow-up
      6
      ·
      30 天前

      10 lines is a bit much, that’s hardly more readable than one.

      Then again, it depends on the language.