Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"any" is not structural typing.


any 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.


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: