Note that I wrote Win32::TieRegistry and I find that the things I most hate about many XS modules are caused by their attempts to provide a Perl-like interface. If you look under the covers of Win32::TieRegistry you'll find Win32API::Registry which provides a very raw transation of the C API for dealing with the Win32 Registry. There are a few minor niceties added to Win32API::Registry's API, but only ones that I was sure didn't take away any of the possible ways to use the C API and that couldn't be more easily implemented in Perl (actually, some of the niceties are implemented in Perl wrappers inside Win32API::Registry).

Trying to make Perl-like interfaces in XS is usually a grave mistake, IMO. Even fairly minor steps in that direction tend to lead to code that is hard to write, hard to debug, hard to extend, breaks easily in the face of the simplest of things (a Perl upgrade or any type of Perl magic such as tie), is more likely to have ref-counting bugs, etc.

Make XS interfaces that are very C-like and expose the full power of the underlying API and then provide Perl wrappers that provide a Perl-like interface. Take Tuppence's advice.

- tye        


In reply to Re^2: Question about module interface style (XS like C) by tye
in thread Question about module interface style by Leviathan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.