• AnomalousBit@programming.dev
    link
    fedilink
    arrow-up
    10
    arrow-down
    20
    ·
    1 year ago

    IDK buddy, I don’t really care to write the same method for five different types (or read the 30 methods with different type signatures) when I can do it with one. I see the exact opposite of your statement, in my experience.

        • wols@lemm.ee
          link
          fedilink
          arrow-up
          13
          arrow-down
          1
          ·
          1 year ago

          Extra steps that guarantee you don’t accidentally treat an integer as if it were a string or an array and get a runtime exception.
          With generics, the compiler can prove that the thing you’re passing to that function is actually something the function can use.

          Really what you’re doing if you’re honest, is doing the compiler’s work: hmm inside this function I access this field on this parameter. Can I pass an argument of such and such type here? Lemme check if it has that field. Forgot to check? Or were mistaken? Runtime error! If you’re lucky, you caught it before production.

          Not to mention that types communicate intent. It’s no fun trying to figure out how to use a library that has bad/missing documentation. But it’s a hell of a lot easier if you don’t need to guess what type of arguments its functions can handle.

    • AeroLemming@lemm.ee
      link
      fedilink
      English
      arrow-up
      10
      arrow-down
      1
      ·
      1 year ago

      I take it your only experience with statically typed languages is with C. It’s a big world out there!

    • SorteKanin@feddit.dk
      link
      fedilink
      arrow-up
      6
      arrow-down
      2
      ·
      edit-2
      1 year ago

      Type signatures help you to know what a function takes and returns. With dynamic typing, I have to read the entire code of the function just to know this (sometimes even this doesn’t tell me what will actually be returned due to duck typing).

      More importantly, type signatures help the compiler verify the types.

      Both of these get more and more important as the code size increases. I’d suggest you widen your horizon about static typing.