The Hidden Power of Humble Interfaces (GopherCon Singapore 2017)

The Hidden Power of Humble Interfaces (GopherCon Singapore 2017)

Learn how to design your own interfaces in Go that are simple yet powerful – just like io.Reader and error. Discover the techniques for correctly identifying the places where interfaces will improve our code, and the specific steps to ensuring that our interfaces are as powerful as they can be.


Aditya Mukerjee

May 26, 2017


  1. 3.
  2. 4.
  3. 5.

    Why use interfaces? • Write less code • Write robust

    code • Write flexible code @chimeracoder
  4. 11.

    What makes the io interfaces powerful? • Abstracting a lot

    of common functionality • Lots of granularity • Plethora of helper functions @chimeracoder
  5. 12.

    What makes error powerful? • Abstracts no functionality • Provides

    no granularity • Provides (almost) no helper functions @chimeracoder
  6. 14.

    Humility and Discipline • Keep interfaces humble • Writing interfaces

    forces you to define the minimum required contract for using your types • Keep interfaces disciplined • Writing interfaces allows the compiler to enforce this contract @chimeracoder
  7. 16.

    Why Gophers avoid interfaces • Afraid of writing an interface

    that is too complicated • Afraid of specifying the wrong methods @chimeracoder
  8. 17.

    How I Learned To Stop Worrying and Love the interface

    • Interfaces reveal the assumptions you’re already making • “If it’s there, you will use it” @chimeracoder
  9. 20.

    Writing interfaces like io.* • Don’t write helper methods until

    you actually find you need them • The contracts provided by each should be minimal • Create composite interface types @chimeracoder