[zeromq-dev] Language binding guidelines

Martin Lucina mato at kotelna.sk
Mon Mar 1 19:16:06 CET 2010


sustrik at 250bpm.com said:
> Right. We should decide which one is nicer:
> 
> z = new ZMQ ();
> s = z.makeSocket (ZMQ::PUB);
> 
> z = new ZMQ::Context ();
> s = new ZMQ::Socket (z, ZMQ::PUB);
> 
> My preference is for the latter. Two reasons:
> 
> 1. It's the current way it is. No need to change the API.
> 2. It's more obvious what's going on. The former example is a bit cryptic.
> 
> However, feel free to outvote me!

I cast my vote in favour of the latter option (keep the Context class).

While hiding the Context class may appeal to people with a "strict OO"
mentality, personally I don't like "magic" happening that hides what is
happening behind the scenes.

Also, "z = new ZMQ ();" is misleading in that it presents to the programmer
that we are "creating an instance of ZMQ", which is not what is happening
at all.

> This means that 0MQ sockets may linger on even after you've closed them, 
> using memory, CPU power, maintaining network connections etc.
> 
> I suspect the same problem may pop up in other garbage collected 
> languages. Anyone any experience here?

This is why we have zmq_close() and zmq_term() and yes, these should be
exposed in an OO API explicitly as has been discussed elsewhere in this
thread. If someone does not wish to use destructors we shouldn't force them
to do so.

-mato



More information about the zeromq-dev mailing list