best "void" return of a member function
Stefan Behnel
stefan_ml at behnel.de
Mon Apr 20 07:28:07 EDT 2009
Stefan Behnel wrote:
> you might want to try to wrap it in a more Pythonic
> look&feel style, that wraps operations and use-cases rather than plain
> functions. That should make it easier to hide things like memory allocation
> and other C implementation details from users, and will generally increase
> the performance of your binding, as it will require less calls for larger
> operations in C space.
Here is an example from your web page:
Sending data is a sequence of commands to prepare a data-package
and one command to send this package.
// get the "send" object from the "msgque" object
struct MqSendS * const send = msgque->send;
// init the data-package
MqSendSTART (send);
// fill the data-package with data
MqSendI (send, myInteger);
MqSendC (send, "myString");
// send the data-package to the server
MqSendEND (send, "IDNT", NULL);
A first thought would be a class "Connection" and a method "send_package" that
takes an arbitrary number of positional arguments, such as
connection = some_source.connect()
connection.send_package(my_int, "myString", end_id="IDNT")
In case you do not know the required data type packing (which is explicit in the
C example), you can either wrap the types in some kind of typing construct
(which might degrade performance, unless you know that you do not need it in
most cases), or define message packing formats in advance in some way, e.g.
similar to Python's "array" module.
Just an idea. Since you appear to be the main author of that library, I assume
that you know best how to make it usable.
Stefan
More information about the Python-list
mailing list