4 ms·
It's a wee bit amusing to see the major icons of duck typing, python and javascript, slowly converge on the truth: static typing is a powerful and useful tool f
by dleslie 6y ago
It's a wee bit amusing to see the major icons of duck typing, python and javascript, slowly converge on the truth: static typing is a powerful and useful tool for mature projects, that should not be dismissed.
Looks like mypy has discovered interfaces. Lovely.
- war1025 6y agoThe difference between "Interfaces" as I have seen them used most of the time, and "Protocols" as mypy uses them, is that usually an Interface is generally part of the inheritance hierarchy. A Protocol is just the same structural subtyping (duck typing) Python has always preferred.
- thechao 6y agoThese protocols match the old Indiana `concepts` pretty precisely; they appear to be more like Haskell type-classes than interfaces -- they're retroactive, not inherited.
- deleted 6y ago[deleted]
- 6gvONxR4sf7o 6y agoSeems more like a convergence towards gradual typing than to static typing.
- ledauphin 6y agoI think you're spot on here. It turns out that a lot of software development is made easier with static types - but also that some of it is _not_. And having access to both without fighting the language can be very powerful. I use static Python types a lot at the application layer, where things have no need to be particularly extensible and having strict definitions for how things are put together brings clarity. But at lower levels of the system, Python's duck typing really shines because I can solve ten slight variations on the same problem with the same code. The same could be said of Typescript, or Clojure+spec, or really any other language where dynamic types are given to you for free (unlike, say, reflection in Java) but types can be added wherever you find them useful.
- dleslie 6y agoType elision or similar is available in many statically typed languages, and has been for a long while.
- glyph 6y agoJust speaking for myself here, I didn’t realize the power of static typing for years and years because the main languages I used with “static types” were C-style; i.e. type checking without null checking. I was vaguely aware of “better” systems but since I had such a wealth of experience with compile-time type-checking catching ~zero bugs, it didn’t seem worthwhile to investigate, and my toy projects didn’t make it clear what I was missing. Having used Mypy in a large practical situation for a couple of years, one of the MAIN advantages of it is the None checking! I would get probably 60% of the utility out of a type checker that could only check for None. Having had this experience now it’s much easier to appreciate the practical benefits of systems like Rust and Haskell, where the type checker is doing real work.