On Wed, Oct 12, 2016 at 5:05 AM,  <sh...@tigera.io> wrote:
>
> I've been writing some code where I have nodes in a processing graph that
> need to notify other nodes when something changes.  I'm using callbacks
> (rather than channels, say) because I want everything to be synchronous.  It
> seems like I've got a choice between
>
> type Foo struct {
>     Callback func(baz Biff) Boff
> }
>
> and
>
> type callback interface {
>     func(baz Biff) Boff
> }
>
> type Foo struct {
>     Callback callback
> }
>
> to represent the callback reference.  Is there a convention (or a good
> argument) for when I should pick one or the other?  Seems like a function
> pointer is more universal (I don't even need an object to be a receiver) but
> maybe an interface is more idiomatic?

There are no hard and fast rules, but I think the func value is more
idiomatic.  And if there aren't any other fields in Foo, I would write
it as

type Foo func(baz Biff) Boff

That said people do use interface values as well, as in go/parser.Visitor.

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