Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Please don't copy DBI's interface. If you want that, you might as will just write DBD::CSV instead. Oh wait, that exists already, and it uses your module, even! How about that: a zillion interfaces ready to use! :)

DBI's interface is inconsistent. It is in part because long time ago, lists were called arrays and references did not yet exist. fetchrow_array returns a list, not an array, but fetchrow_arrayref does return an arrayref, not a listref (listrefs do not exist (\@_ is an arrayref!)).

Besides that, I think the fetch part is redundant. Well, for DBI it is, at least. Perhaps not for your module. All you do with an executed STH is fetch stuff. Another redundant part of the overly long method names is ref. Since it is impossible to return an array or hash, just array or hash is enough to indicate that a reference is returned. And the row versus all thing can be reduced to singular or plural.

For DBIx::Simple, this is why fetchrow_arrayref is just array and fetchall_arrayref is just arrays (17 to 6, that's almost 66% less). As an extra handy feature, in list context, arrays returns a list of arrayrefs instead of a (reference to an) array of arrayrefs, so it can more easily be used with foreach. hash and hashes speak for themselves. I think list explains what it does (at least in list context) very well too.

The best thing about these method names isn't that they are more consistent, or that they are more logical. It is that they require much less typing and because they are shorter, are also much easier to read (especially the difference between fetchall_someref and fetchrow_someref is hard to spot, because humans1 don't really pay much attention to what's in the middle).

I'm not saying you should use what DBIx::Simple uses. I am asking you to reconsider your current DBI-ish method names. Yes, people already know DBI and that makes learning easier, but your module isn't DBI and DBI's method names aren't great even for DBI.

(Add to this that you should replicate bugs and quirks that DBI has to not surprise people. If things look enough alike, people expect them to be exactly the same...)

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Update:
1 - I'm not sure whether Java coders are human ;)

In reply to Re: Text::CSV_XS - proposed new interface by Juerd
in thread Text::CSV_XS - proposed new interface by jZed

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found