I've written quite a bit of XS code and read even more XS code that other people have written.

This has convinced me that the best way to use XS is to avoid it as much as possible. By this I mean, if you can do something in Perl, then you probably should do it in Perl.

I see lots of XS code that tries to build an array, pull values out of a hash, create objects (bless), etc. These modules always end up doing a pretty poor job of this (as well as causing the authors lots of pains trying to get the code to work). For example, such code won't handle tied variables. Even worse, the APIs that result are always less flexible and less Perl-like and so are a pain to use.

And I've had the dubious task of trying to debug, patch, and enhance some of these modules. Doing that to "Perl written in C" really, really sucks. With most modules, I can use the Perl debugger to quickly find problems and then I can work around them easily, often without even modifying the module. With these heavy-XS modules, finding the bugs are much, much, much, much harder, I can rarely work around them when I find them, and usually have to recompile the XS code.

Much better is to have a Perl subroutine that does the Perlish things and puts the items in a format that is easy for C to make use of, and then have the XS only do things that are easy to do in C and hard to do in Perl.

And so I encourage you to use Inline::C since it is a wrapper for XS that encourages you to use only simple arguments which might get you to put more in your Perl and less in your C. It is also easier to use.

        - tye (pack "d*",@_)

In reply to (tye)Re: Inline::C vs. XS vs. SWIG by tye
in thread Inline::C vs. XS vs. SWIG by Anonymous Monk

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.