• atzanteol@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    18
    ·
    2 days ago

    God yeah - this hits hard with me. I work in a place where the DRY principle is chanted like a mantra and I have to push back against it constantly. It’s like the one principle jr. devs learn (along with “never hardcode anything”) that just gets applied to everything whether it makes sense or not.

    "These lines of code are very similar, let’s factorize them ! "

    “We should take three simple functions that run similar (but different) things and make them call a single large complicated function that takes a parameter that tells it how to execute!”

    ::shudder::

    • Hasherm0n@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      6 hours ago

      You just reminded me of the early days at a company I worked where the factory pattern was absolute. Their were interfaces and factories for fucking DTOs. It was insanity! That was the place where I really learned the concept of “cargo cult”

      • atzanteol@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        5
        ·
        8 hours ago

        “The one that makes sense”

        Patterns and principles are guidelines, not rules. You don’t want to just apply them blindly.

        You need to balance principles. Over-applying the DRY principle can lead to more complex logic that’s harder to understand than if you just wrote code in-line.

      • fruitycoder@sh.itjust.works
        link
        fedilink
        arrow-up
        2
        ·
        17 hours ago

        The rule I see is functions should be fairly atomic and almost obvious what they do in context of the code.

        At least for my small brain that’s how I like it. I can understand some complex abstractions but rembering that actually this function behaves in three different ways depending on what flag is set is awful. It means you could look at one example and be totally wrong in another. Ideally you could guess the functions purpose even in a black box setting based on inputs outputs and the name should then make it obvious.

        • buffing_lecturer@leminal.space
          link
          fedilink
          arrow-up
          3
          ·
          16 hours ago

          The example that the other commenter gave did not require the user to input the flags. As far as I understand, they mean there would be a number of secondary functions that will call the other with the correct parameter.

          • fruitycoder@sh.itjust.works
            link
            fedilink
            arrow-up
            3
            ·
            13 hours ago

            Fair point. My point still stands on it breaking the black box test. Where the input can wildly effect the logic that creates the output.