A few other thoughts on this:

1 - Method values mean that you can get a function type that accesses state 
without closures over local variables:

a := &myStruct{}
// b is a SomethingDoer function
b := a.DoSomething

e.g. https://play.golang.org/p/SVY8rQ8WR_

2 - Method values also mean that multiple methods can be provided that 
satisfy a function type but operate on the same data, something that 
requires creating new types to do with interfaces (though very do-able - 
see SortWrapper example in https://golang.org/pkg/sort/)

a := &myStruct{}
// b and c are both SomethingDoer functions
b := a.DoSomethingAlphabetically
c := a.DoSomethingChronologically

3 - (In my view a minor point) - It's clearer at the call site as to which 
function is being called without an interface:

needsADoer (a.DoSomething) versus needsADoer (a)

I tend to use interfaces for things with multiple methods that need to work 
together and function types for single method abstractions.

-- 
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