3 ms·
> Furthermore, the duck typing paradigm further warrants Python's position here. Going to have to disagree with you here. Have you ever used Typescript? You ca
by phailhaus 7y ago
> Furthermore, the duck typing paradigm further warrants Python's position here.
Going to have to disagree with you here. Have you ever used Typescript? You can have duck typing and a proper static type system at the same time without devolving into Java. Furthermore, you can write Typescript without using types at all! Simply have everything default to `any`, and it reduces back down to Javascript.
Python unfortunately decided to go in a direction that is the worst of both worlds. You can add type hints, but they do nothing without a 3rd party tool (?!). This means I can enter a code base, see type hints, and still have no guarantee that the types are what they claim to be. Instead, we have to rely on company-specific build processes to give us that static guarantee. And if you're not lucky enough to work in a codebase that runs mypy before merging, you might as well throw those type hints out the window.
- choppaface 7y agoI’ve used Scala which offers a similar experience. You still fall into the type game for generics, for example when using the just the Visitor pattern. Dealing with JSON is also a pain in any language with static types. I don’t believe you can really have duck typing and static at the same time unless you throw out the static checks and mark things as “Any” (or the equivalent). The beauty of Pythonic duck typing is that interfaces need not have any type declaration and furthermore the user can use dicts with complex structure (and declaring that structure with type annotations wouldn’t add any value over examples and/or unit tests). What makes Scala and modern C++ great is they offer nice interfaces for expedient use of the static type system. But there’s still plenty of room for the Pythonic approach of no static types at all.
- phailhaus 7y ago> declaring that structure with type annotations wouldn’t add any value over examples and/or unit tests Types can be exported, which means that consumers of your library have an actual guarantee of what you are returning, rather than just hoping that the docs are up to date. Javascript is the ultimate duck-typed language given that everything is really just an object, and TypeScript is extremely effective at managing it. I can't see why Python would be any different.
- choppaface 7y agoright, a lot of python code either doesn't result in libraries (or even documentation), or library APIs often tend to focus on dicts or integral types. successful libraries like numpy and pandas focus on a very small set of well-defined objects and leverage duck typing for containers (and runtime casting for interop with native code). I'm not saying arguments in favor of static typing and annotations are invalid, but rather it's a mindset that can make much of python look very foreign. the norvig spellchecker is a key example of swath of python code where static types are essentially irrelevant.