[zeromq-dev] Language binding guidelines
Martin Lucina
mato at kotelna.sk
Mon Mar 1 19:31:33 CET 2010
cremes.devlist at mac.com said:
> >> For the Java and Ruby cases, why not move to a factory pattern where
> >> a class method instantiates and returns an object containing the
> >> context and all of the other bits?
> >> // Java z = ZMQ.factory(); s = z.makeSocket(ZMQ::PUB);
> >> # Ruby z = ZMQ.factory s = z.make_socket ZMQ::PUB
> >> This way there isn't any confusion about instantiating what looks
> >> like a namespace.
> >
> > Yes. That's the same thing. It just renames context to factory.
>
> Sure, but at least the syntax isn't as confusing as "new ZMQ()" which
> looks odd in every case.
Indeed. The obvious compromise would seem to be:
ctx = new ZMQ::Context();
sock = ctx.socket(ZMQ::PUB);
And following on from that:
sock.setsockopt(ZMQ::SUBSCRIBE, "");
sock.connect("tcp://192.168.1.1:5555");
Note that I'm deliberately keeping the method names as similar as possible
to the corresponding C zmq_xxx() function, since the C API documentation
is the master reference for any 0MQ developer. This is important, a
developer using XYZ language binding should not have to rely on their
binding documenting (or duplicating the documentation of) the core 0MQ
functionality.
-mato
More information about the zeromq-dev
mailing list