3 ms·
Go interfaces are explicit, not implicit, the difference is more where they are defined. With subtypes the interfaces are defined with classes(an animal does t
by grey-area 2y ago
Go interfaces are explicit, not implicit, the difference is more where they are defined.
With subtypes the interfaces are defined with classes(an animal does this and that), with interfaces they are defined at the point of use (I accept a param that does this and that).
Interesting that gosling said at one point he felt including classes (i.e. inheritance) in Java was a mistake. I feel this is one thing Go got right compared to many other languages. Turns out inheritance just isn’t very helpful.
- Jtsummers 2y ago> Go interfaces are explicit, not implicit, the difference is more where they are defined. That's not what the blog author wrote so what are you responding to? What they actually wrote: >> If a Go struct implements the same functions as an interface, it implicitly implements the interface. And that's correct except they use the term "functions" instead of "methods". But most people won't get confused by that distinction. https://go.dev/tour/methods/10 https://go.dev/tour/methods/10 - "Interfaces are implemented implicitly"
- grey-area 2y agoThey are declared explicitly and implemented implicitly. Thus the analogy the author is trying to make with magic methods in more dynamic languages like python or ruby is inaccurate and IMO misleading.