3 ms·
Is it because of the kinda built-in duck typing, for want of a better word? The thing where if you have a method (or methods) that matches the signature of meth
by EdwardDiego 5mo ago
Is it because of the kinda built-in duck typing, for want of a better word? The thing where if you have a method (or methods) that matches the signature of method(s) of an interface, you implement the interface without explicitly declaring so?
- 9rx 5mo ago> for want of a better word Structural typing is the term typically used to describe "static duck typing".
- catlifeonmars 5mo agoI’d describe structural typing as a special case of duck typing FWIW.
- 9rx 5mo agoI suppose. That special case is that it is evaluated statically, whereas duck typing is evaluated dynamically. That's the whole difference between them. They are otherwise identical concepts. But who is to say that dynamic evaluation isn't the special case?
- Merovius 5mo agoMore specifically, it is because of interface type assertions – the fact that if you have a value of some interface type (e.g. `any`), you can dynamically assert that it is another interface type (e.g. `io.Reader`). A good example of that is `io.Copy`: https://cs.opensource.google/go/go/+/refs/tags/go1.26.3:src/io/io.go;l=408 https://cs.opensource.google/go/go/+/refs/tags/go1.26.3:src/... This aspect is what prevents you from statically knowing which interface-implementations you need to generate for a specific concrete type. There could always be new ones added at runtime.