Hacker News new | ask | show | jobs
by stuartweir 3768 days ago
Have you had much experience with Go? Go interfaces and Java interfaces are different beasts... Go's interfaces are incredible...take a look at Reader and Writer from the io package as an example - they're two of the most powerful interfaces in the language, and extremely flexible.
2 comments

> Go's interfaces are incredible...take a look at Reader and Writer from the io package as an example - they're two of the most powerful interfaces in the language, and extremely flexible.

Yup. I literally just gave a talk at two Go conferences in the last two weeks (GopherCon India and GopherCon Dubai) about the io.Reader/io.Writer interfaces specifically. They're deceptively simple on the surface, but they're insanely powerful once you 'get' them.

It would be interesting to know more about the power you seen in `io.Reader` and `io.Writer`. They seem to say, effectively, that every type implements serialization from bytes and serialization to bytes. Generic serialization is not so unusual but maybe in the context of Go can be so much more?
Interfaces in golang are error prone. It's easy to inadvertently implement an interface you didn't mean to. It's also difficult without the aid of some tooling, to determine which set (or whether at all) of interfaces a given structure implements.

There was a blog post a while ago about how golangs's interfaces caused issues in production because they're implicit.

Check out type classes for a superior way to solve this issue (e.g. what Scala or Rust do).

I can't think of a problem caused by inadvertently implementing an interface?
Client code relying on the fact that your class implements that interface when it wasn't intentional and might change perhaps?