129 points · by type0 · 9y ago · 26 comments
That should be where you are heading, because contracts should be separated from implementation, things should not be tightly coupled, etc. This is good programming practice. How can you be opposed to accepting interfaces instead of implementations, especially in a standard library or the standard tooling for the language?
A concrete example: If I have a NewFoo function that returns a Foo and a FooTaker function that accepts a FooInterface, I can't assume that new features I add in NewFoo are usable from FooTaker. If FooTaker just took a Foo, there would be no problems.
This is, I think, the best rule of thumb for when to use an interface: If you expect consumers of your library to write their own data types that could be used by your library, define an interface they can satisfy. Otherwise just produce and consume a struct you control -- it will be much more flexible and maintainable in the long run.
Do you have concerns about interface arguments?
Rationale here: https://medium.com/@cep21/what-accept-interfaces-return-stru....
Yeah - build your application as a Caddy plugin, then you can use their routing / ACME handling...
There are a lot of similarities. Hopefully Go developers can bypass some of the pitfalls along the journey.