4 ms·
> Go's one language innovation is to not require an interface implementation to declare the interface it implements. Uh? How is that innovation? 100% of mainst
by hota_mazi 3y ago
> Go's one language innovation is to not require an interface implementation to declare the interface it implements.
Uh? How is that innovation? 100% of mainstream languages that I can think of that predate Go do this.
Can you name one programming language that we should care about which, once you define an interface, FORCES YOU to provide an implementation of said interface?
- mb7733 3y agoI think you misread the sentence you quoted.
- lmm 3y agoThe point is that in most languages something doesn't implement an interface unless it declares that it does so; in Java or C# if you don't explicitly write "extends Writer" then your type doesn't implement Writer, even if you implemented all the methods of Writer. Whereas Go offers something similar to e.g. Python's behaviour where things are "duck typed": you don't have to explicitly reference a particular interface, you just implement the right methods. Of course in (traditional) Python that works because the language doesn't have real ("static") types at all. Having "static duck typing" is pretty rare - TypeScript now has it (and Python itself sort of has it), but when Go did it it was something that was pretty much new for mainstream languages. (IMO it's a misfeature; having explicit interfaces communicates intent and allows you to do things like AutoCloseable vs Closeable in Java - but that's a matter of judgement)
- masklinn 3y ago> The point is that in most languages something doesn't implement an interface unless it declares that it does But that's not a requirement. Haskell did nominative "interfaces" (typeclasses) and post-creation conformance 20 years before Go happened.
- lmm 3y ago> Haskell did nominative "interfaces" (typeclasses) and post-creation conformance 20 years before Go happened. Not the same thing, yes you can have orphan instances (with a flag) but you still need an explicit typeclass instance somewhere. Whereas Go interfaces are structural rather than nominal. (And much as I might wish otherwise, Haskell barely qualifies as a mainstream language)