3 ms·
> But it's simply a fact that using the `any` type means that certain properties of the program can't be checked at compile time Yes, structural typing removes
by 9rx 2y ago
> But it's simply a fact that using the `any` type means that certain properties of the program can't be checked at compile time
Yes, structural typing removes the ability to check certain properties at compile-time. That doesn't make it typed like Python, though.
- int_19h 2y ago"any" is not structural typing.
- 9rx 2y agoany isn't a special type. It is an alias for interface{}. The empty set is trivially satisfied by all types, but obviously can be narrowed as you see fit.
- int_19h 2y agoI know, but having a type that is a supertype of everything is still not structural typing. Structural typing naturally has such a type, yes, whereas with nominal type systems it has to be explicitly introduced - but that still happens often enough, e.g. object in Python or System.Object in C#. OP's point was that `any` in Go is much akin to duck typing in Python because in both cases the type check happens at runtime at the moment you're about to use the object. Yes, in Go, technically there's a separate step of downcasting to some interface type before you invoke the members, and it's that downcasting which fails, but c'mon, this is a pedantic distinction without a meaningful difference in practical usage scenarios of `any` to work around language limitations. The relevant thing is that it has all the same downsides.