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

That interface isn't great, but that interface isn't coming from Go. I realize you aren't claiming it is, and you're absolutely right that Go's interfaces don't automatically "solve" issues of bad design. Programmers are free to come up with bad interface designs in Go just as easily as they came up with bad class designs in Java or C++. This is just to avoid confusion for people who aren't generally familiar with Go but read this article.

The Go standard io library has a Reader interface:

  type Reader interface {
      Read(p []byte) (n int, err error)
  }
a Writer interface:

  type Writer interface {
      Write(p []byte) (n int, err error)
  }
and a ReadWriter interface which uses type embedding to combine both:

  type ReadWriter interface {
      Reader
      Writer
  }
Idiomatic Go will break interfaces up into pretty discrete bits of functionality and use type embedding to build up more complex interfaces. The article does show this a little bit with its seekable interface but fails in some other areas and I kind of wish it just used the real io package interfaces or else examples of something not covered better by the actual Go standard library.


Well, sure, but Reader and Writer are interfaces existing in java too :)

Anyway I think we agree on the general issue, but actually I suspect go's approach _does_ solve some bad design issues that crop up in common OO, namely the fragile base class one.

I just don't think it impacts the misspecification one.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: