::Simple

As of this morning there are just under 250 modules on CPAN matching ‘::Simple’. I take a certain amount of blame for this. I’ve released a couple myself, and my kitchen has a credit as the birthplace of Test::Simple.

But I like to think that in those cases the module really does deserve the ‘simple’ moniker. Perl’s spreadsheet modules are notoriously complex, and there’s no need to jump through all the hoops of two-dimensional cell access and data vs. formatting if all you want to do is read or write each row as an array. Similarly, Test::Simple has one trivial test function that is all a beginning test-writer needs to get into the way of writing tests, and there’s a clear migration path up to Test::More.

But somewhere along the line ::Simple seems to have mutated into ::I::Don’t::Like::The::Normal::Syntax. Take DBD::mysql::SimpleMySQL. Ignoring the fact that it’s in completely the wrong namespace as it’s not a driver, I’m at a complete loss to see how it’s “simpler” than, well, anything really.

Now, I’m obviously biased, but even the example in the docs makes my brain hurt:

my $select = ['Passwd.*', 'UsrGrp.UsrGrpName'];
my $from = ['Passwd'];
my $joins = [];
push @{$joins}, join_struct("PasswdHostGrp", "Passwd.PasswdID", "PasswdHostGrp.PasswdID");
push @{$joins}, join_struct("UsrGrp", "Passwd.PrimaryGroupID", "UsrGrp.UsrGrpID");
my $wheres = "PasswdHostGrp.HostGrpID IN ('group1', 'group2')";
my $arrayref = dbselect_array($dbh, build_select($select, $from, $joins, $wheres, 0))

I can understand trying to make it slightly easier to build SQL dynamically, or trying of provide a way to abstract and package up SQL patterns, but I really don’t understand programmers’ fascination with trying to completely reinvent SQL. The basics are really quite straightforward, especially at the level that these modules are able to ‘hide’ from you. And it’s going to be much simpler and more powerful when you eventually need to do something considerably more complex. There’s really no substitute for learning how to use SQL if you’re going to work with databases.

In fact I’d say that trying to reimplement SQL is a move in exactly the wrong direction. Especially in a dynamic and flexible language like Perl, it’s good practice to invent little mini-languages for the domain in which you’re working. But, of course when working with databases there’s no need to invent the language – it already exists!

Somehow I doubt this will stop the proliferation of modules trying to do away with SQL. Soon we’ll probably have as many database abstraction libraries as we do templating systems…

Leave a Reply

Your email address will not be published. Required fields are marked *