2 ms·
I’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. Dealin
by choppaface 7y ago
I’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.