On Thu, 2011-01-20 at 13:08 -0500, Jeff Squyres wrote:
> On Jan 20, 2011, at 12:32 PM, Samuel Thibault wrote:
> 
> > Apart from these nasty details, I like the interface style, thanks for
> > the nice contribution ! :)
> 
> +1
> 
> I was more curious on whether the hwloc bindings interfaces for perl and 
> python would be similar.  It looks like they will be a bit different.  This 
> is obviously not a problem -- I was merely curious.

>From my (very personal) point of view we speak about wrappers around the
C API. A wrapper should mimick the C API as much as possible in function
and style, and may optionally provide additional things that are
specific for the used language.

For the Perl binding I decided to implement the C API mostly as-is, that
means I provide functions with the same name and arguments like found in
the C API. This should aid people that know the C API, and aids me in
providing the documentation of the wrapper. I simply documented what is
implemented, and point to the hwloc API docs for details. And, to be
honest, I always have to take a look into the API docs when I'm coding
with hwloc in C or in Perl, because I cannot remember these long names.
It would take twice the time for me if I would need to read two docs to
achieve similar things in different languages.

In addition I thought it would be a good idea to provide an
object-oriented interface, because this is easy to do in Perl XS, and
because coding is easier and nicer with OO in Perl. Perl objects are
simple hashes, that are blessed into some namespace. Methods in a
namespace are simple functions. The connection between an instance of a
Perl object and the method that operates on its data bases on the same
namespace of the object instance and the method, and the convention that
the first argument of the method has to be a pointer to the object
instance. So I coded the wrapper for the C function in the XS, and if
the function has a topology pointer as first argument, I simply define
an alias of the function in the namespace used for topology objects.
This gives both non-OO and OO variants without additional coding, and
one is free to invent OO method names by retaining the function name of
the non-OO API. In other words, hwloc_topoloy_get_depth($t),
$t->get_depth and $t->depth use the same wrapper code.

The only thing I was wondering about are these OO method names, which I
had to invent them myself. If there is some need to synchronize these
with the python binding, we may agree about them. Backwards
compatibility of the Perl binding is not a real problem, since there may
be many aliases for a function in the base XS code.

Regards BK

-- 
Dr. Bernd Kallies
Konrad-Zuse-Zentrum für Informationstechnik Berlin
Takustr. 7
14195 Berlin
Tel: +49-30-84185-270
Fax: +49-30-84185-311
e-mail: kall...@zib.de

Reply via email to