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

> 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?



The 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)


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


> 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)


I think you misread the sentence you quoted.




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

Search: