Nothing to say in RPC method (or "void in go?")

1,891 views
Skip to first unread message

Jeremy Thorpe

unread,
Feb 9, 2012, 1:15:13 PM2/9/12
to golan...@googlegroups.com
Hi all,

What is the idomatic way to write a function signature of a function
that I want to have made available for remote access via the RPC
package (http://weekly.golang.org/pkg/net/rpc/) that has no input
and/or no output? There is no void, so I have been writing:

func (_ *Receiver) DoNothing (_ bool, _ *bool) error {
}

I picked bool because it has the least information of any primitive
type, but I don't think this is a particularly good reason. Would an
empty structure be more idiomatic? Is there something more like C's
void?

Thanks,
-Jeremy

Kyle Lemons

unread,
Feb 9, 2012, 2:27:59 PM2/9/12
to Jeremy Thorpe, golan...@googlegroups.com
Technically, struct{} has the least possible information.  You might be able to get away with interface{} too and just passing nils.  Also, not specifying the _ in the receiver is still valid.

Jeremy Thorpe

unread,
Feb 9, 2012, 2:48:55 PM2/9/12
to Kyle Lemons, golan...@googlegroups.com
Denis,

I realize that I can write a function that simply takes no arguments.
My problem is that such a function would definitely not be available
for remote access through the rpc package
(http://weekly.golang.org/pkg/net/rpc/). It's looking for a fairly
specific function signature.

Kyle, thanks.. I think I will use:

func (_ *Receiver) DoNothing (_ *struct{}, _ *struct{}) error {
}

Strangely, I can get rid of both _'s, but if I need one argument to be
named and want the other to be unnamed, and omit the _, I get "mixed
named and unnamed function parameters". Perhaps there's some
ambiguous corner case that this rule avoids.

Thanks!
-Jeremy

Kyle Lemons

unread,
Feb 9, 2012, 3:14:44 PM2/9/12
to Jeremy Thorpe, golan...@googlegroups.com
Kyle, thanks.. I think I will use:

func (_ *Receiver) DoNothing (_ *struct{}, _ *struct{}) error {
}

Strangely, I can get rid of both _'s, but if I need one argument to be
named and want the other to be unnamed, and omit the _, I get "mixed
named and unnamed function parameters".  Perhaps there's some
ambiguous corner case that this rule avoids.

It's mostly the receiver type that I would elide.  The _ function arguments are nice and clearly ignored, IMHO.

Rob 'Commander' Pike

unread,
Feb 9, 2012, 3:20:02 PM2/9/12
to Jeremy Thorpe, Kyle Lemons, golan...@googlegroups.com
func (*Receiver) DoNothing(_, _ *struct{}), error

-rob

Jeremy Thorpe

unread,
Mar 13, 2012, 1:45:37 PM3/13/12
to Rob 'Commander' Pike, Kyle Lemons, golan...@googlegroups.com
Incidentally, when the server code is Rob's code:

func (*Receiver) DoNothing(_, _ *struct{}), error

Should the client code look like this?

h.Call("Receiver.DoNothing", struct{}{}, nil)

-Jeremy

Reply all
Reply to author
Forward
0 new messages