5 ms·
Python isn't about types, it is about protocols. If you are thinking about the type of something while writing the code, then you are transcoding C++ or Java i
by dbcurtis 11y ago
Python isn't about types, it is about protocols. If you are thinking about the type of something while writing the code, then you are transcoding C++ or Java into Python. The important thing about a Python instance is not the type, but the protocols that the instance supplies.
Switching gears and thinking about code validation for a minute, I agree, protocol conformance checking is a much more difficult problem to resolve at compile time, at least they way Python duck types support protocol definitions.
- solidsnack9000 11y agoAren't protocols just a particular kind of abstract type? In Swift, "interfaces" or "traits" are literally called protocols.
- zaro 11y agoIf you go that route, anything can be abstract type. I tend to see it like: type is what this object actually is, and protocol is how we interact with it.
- solidsnack9000 11y agoI see where you are going. But I'm sure we can agree that both concrete types and protocols would be handled by a "type checker". If ever there were a language where you'd want to be looking at protocols and not concrete types most of the time, it would be Python.
- duaneb 11y agoIt's objective-c terminology originally. Interfaces, traits, protocols are all fairly interchangeable. Objective-c already used @interface to declare the public method list of a concrete type, so it's a little odd in this case.