[zeromq-dev] What do I need to do to create a subproject of the libzmq?

john skaller skaller at users.sourceforge.net
Mon Feb 13 07:40:42 CET 2012


On 13/02/2012, at 2:54 PM, niXman wrote:

>>        ZE::init (2);
> In my opinion, is too complicated.

Like I said .. **look at the Felix binding**. 
It isn't complicated at all.

It is, in fact very much simpler than what you are likely to do.

For example:

  proc send_msg (s:zmq_socket) (m:zmq_msg_t) => 
    int_to_proc$ zmq_sendmsg (s,m,ZMQ_XMIT_OPTIONS_NONE);

Here, send_msg does not return an error code, zmq_sendmsg does.
[A proc is a function returning void]

To convert one to the other we just call the error handler int_to_proc:

	int_to_proc (zmq_sendmsg ( .. ))

I don't see how you can possibly consider that "complicated" :)

int_to_proc is a fixed function that calls ehandler<T> if it finds
an error:

  proc ehandler() {
    err := errno;
    println$  "Exit due to ZMQ error "  + str err + ": " + ZeroMQ::zmq_strerror err;
    System::exit err.int;
  }

The corresponding C++ is obvious. This is a *particular* error handler,
which prints a diagnostic and exits the process.

All the client has to do is define that with an associated dummy type.

This is absolutely not complicated! The point is, it completely removes the
responsibility for handling errors from your code. Your code has
to *detect* the errors.


> std::shared_ptr<zmq::session> session;
> try {
>   session.reset(new zmq::session(...));
> } catch ( ... ) {
>   ....
> }

This is extremely ugly and it isn't right. No one wants to
catch exceptions around every statement. If they did
you'd just use an error return. Besides, how the heck
do I know what to catch?

And if you move the try/catch outwards, it's even worse,
because then you don't really know where it was thrown from.

You do realise your example can throw an out of memory thingo?

Exceptions, as in Java, C++ and most other languages, are really
bad, they're worse than gotos. At least gotos fail to compile if their
targets aren't found, and the targets are always local.

There's some new theory that provides a more constrained model
that can't fail. It's best to avoid exceptions otherwise, unless
they're purely for diagnostic purposes, and the only reason to catch
them is to print the diagnostic.


> And yet, what should I do to create a subproject?

Make a new project on GitHub.
Bindings other than the C one don't really belong in the zmq repo.

--
john skaller
skaller at users.sourceforge.net







More information about the zeromq-dev mailing list