Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Follow the Interface?

by ViceRaid (Chaplain)
on Jul 24, 2003 at 15:04 UTC ( #277568=note: print w/ replies, xml ) Need Help??


in reply to Follow the Interface?

I'd come to a similar opinion as tye above, though perhaps for a slightly different reason. I know no C or C++, and very little about the specifics of XS. I know a good deal of Perl. I'm probably not unusual: if the intended audience for your new Perl interface module is Perl developers, you're guaranteed that everyone in that audience is going to know something about Perl - at least how to download, install and use a module - whilst you can't say anything with confidence about how much C they know.

The most important thing is to supply those Perl developers with a library-centric interface and enough documentation to get started using it. They may well hate the interface as "un-Perlish". If they loathe it enough, and have enough Perl to understand packages and modules, they can sweeten the interface to taste. Well, they don't even need to understand packages: if they can write a function, they can hide the nastiness of your library-centric module all they want.

As an example, take a look at the HTML parser modules on CPAN. Many of them derive from the c-based parser in HTML::Parser. The interface of HTML::Parser probably isn't to the taste of most people (a few years ago, I tried and failed several times to understand it), but it doesn't matter, because there's lots of people willing to step in and provide more "perlish" interfaces (whatever that means to them). Hence HTML::PullParser, HTML::TokeParser, HTML::TreeBuilder, HTML::TokeParser::Simple, and so on.

Recently, I wanted to use the library version of HTML Tidy. Without disrespect to the author, what's provided for Perl is a pretty bare (SWIG-ified) interface to the underlying C calls. To me it's ugly to do:

my $tidy = HTML::Tidy::Document->new(); $tidy->Create(); $tidy->SetErrorFile('/dev/null'); $tidy->OptSetValue( $tidy->TidyBodyOnly, 1); $tidy->ParseString($messy); my $tidied = $tidy->SaveString();

The underlying C-constants are exposed ($tidy->TidyBodyOnly) and there's steps that are meaningless in Perl ($tidy->Create()). And I don't like the method naming convention. But it's simple for me as a Perl developer to make a functional interface I like, such as:

my $tidied = html_tidy($messy, 'TidyBodyOnly' => 1)

That hides all the C messiness. The point being: I could never have written the C interface; I simply don't know how. But I - or any other competent Perlista - can wrap your generously-provided C-interface just as they wish.

Let a thousand interfaces bloom
ViceRaid


Comment on Re: Follow the Interface?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://277568]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-12-20 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls