• o11c@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    That still doesn’t explain why duck typing is ever a thing beyond “I’m too lazy to write extends BaseClass”. There’s simply no reason to want it.

    • lysdexic@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I already explained it to you: protocols apply to types you do not own or control, let alone can specify a base class.

      You just specify a protocol, specify that a function requires it, and afterwards you can pass anything to it as-is and you’ll be able to validate your calls.

        • lysdexic@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          1 year ago

          I’m not sure you understand that what a union does or does not do is completely irrelevant and besides the point. Python’s protocols add support for structural subtyping, and enable both runtime and build-time type checks without requiring major code changes. Don’t you understand what that means?