• @AeonFelis
    link
    269 months ago

    That’s what generics are for.

      • @[email protected]
        link
        fedilink
        129 months 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.