On Fri, Jul 8, 2016, at 01:39 PM, Viktor Kojouharov wrote:
> It would have been quite useful for the stdlib to define a logger
> interface, so that third party loggers would implement it and allow
> for easier switching between them
 
Maybe, but one strength of Go's interfaces is that consumers of packages
can define their own interfaces and don't need to rely on the package
creator. In fact it gives the consumer a lot of power since they can
define just the few methods they need. This allows a lot more
interoperability than everyone trying to agree on the one true logger
interface.
 
In my experience, a rough rule of thumb is that interfaces are best used
as a way of configuring your code for different behaviours. If you need
to be able to swap logging implementations then define the minimum
interface you need to be supported and then either directly use the 3rd
party packages you need or write an adapter.
 
-- Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to