• fuck_u_spez@lemmy.fmhy.mlOP
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    2 years ago

    Thanks for the write up, but as I said, I know and I’ve read all about that already. I still cannot see, why a simple function argument and an interface isn’t enough (you can probably already call that “dependency injection” if you want to get fancy)

    I guess I have just divorced with OOP and the “necessary” “design patterns”…

    Things are more simple and less boilerplaty now for me :).

    • bjornsno@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      My brother in Christ, that is dependency injection. Just because you don’t want to call the spade a spade anymore doesn’t make it not so.

        • jvisick@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          2 years ago

          “Dependency injection” is just a term for providing a function or method with its dependencies rather than making the function go and gather them itself.

          It’s (typically) done through parameters, but it’s still more specific than just invoking a function. It describes how that function was written and the reasoning for certain parameters. To the other commenter’s point, you’ll have a hard time communicating about your code with other developers if you refuse to use the term dependency injection just because you don’t like OOP.

        • bjornsno@lemm.ee
          link
          fedilink
          arrow-up
          1
          ·
          2 years ago

          You’re gonna have a tough time talking to others about your code if you don’t agree on common terminology. Function invocation is just function invocation, it doesn’t say anything about the form of the parameters or composition. Dependency injection is a well known and commonly understood method of facilitating decoupling and composition by passing a function’s dependencies as parameters. From your comments you’re talking about the second, but refusing the name, for… reasons?

          • philm@programming.dev
            link
            fedilink
            arrow-up
            0
            ·
            2 years ago

            I guess I’m a little bit too long already in the functional/data-driven world (after being a decade in OO languages (IMO too long…)). In OOP you may need a separate term for that.

            But I think it’ just not really necessary in functional programming, it’s just another parameter when calling a function, that may be a somewhat type-constrained generic (for testing e.g. with a mock implementation).

            I mean function parameters are somewhat dependencies anyway, so should I call all my parameters now dependencies and invocation “injection”?

            • bjornsno@lemm.ee
              link
              fedilink
              arrow-up
              1
              ·
              2 years ago

              Thought you were OP for a second there, as they were talking about composability. Whether it’s dependency injection or not depends on what shape your parameters take. If you’re doing functional programming and you’re passing handlers and connections etc. as params, that’s dependency injection. If you’re only passing strings and objects and such and the function has to do a bunch of logic to decide how to handle its params, that’s not dependency injection.