Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: A brief survey of the DBI usability layer modules on the CPAN

by Aristotle (Chancellor)
on Nov 03, 2005 at 15:15 UTC ( #505386=note: print w/ replies, xml ) Need Help??


in reply to Re^3: A brief survey of the DBI usability layer modules on the CPAN
in thread A brief survey of the DBI usability layer modules on the CPAN

As I’ve said before in this thread, that is roughly what I already do. And as I’ve already responded to fokat, I find ORMs unhelpful for this approach as well.

The primary advantage of an ORM would seem to be that it avoids leaking database queries into unrelated code all over the place. However, as you point out, despite appearances, that couples the code too closely with the database. So there should indeed be a higher-level abstraction layer than just the ORM.

Of course, how this extra layer’s innards are written is not a concern to the calling code. It’s also clear that internally, this layer is inherently coupled strongly with the database. Fine, so you could use an ORM to simplify this code. But you can do that just as well using something like SQL::Abstract – and that way you also avoids the overhead and opacity introduced by an ORM.

So I find that depending on the side from which you look at it, ORMs are either too much abstraction or too little, but never right.

Makeshifts last the longest.


Comment on Re^4: A brief survey of the DBI usability layer modules on the CPAN
Re^5: A brief survey of the DBI usability layer modules on the CPAN
by siracusa (Friar) on Nov 03, 2005 at 15:59 UTC
    Fine, so you could use an ORM to simplify this code. But you can do that just as well using something like SQL::Abstract and that way you also avoids the overhead and opacity introduced by an ORM.

    But then you miss out on the advantages of dealing with objects instead of just bare row and column data in the calling code. And if you decide to dress up the rows returned by DBI-style queries by using that data to initialize objects, well, you're basically writing your own mini ORM at that point.

    So I find that depending on the side from which you look at it, ORMs are either too much abstraction or too little, but never right.

    I find that they're a happy medium that I rarely need to stray far from in either direction. I've already described when I do when I need something lower-level. In the cases where a higher-level abstraction is needed, I tend to aggregate ORM objects inside the higher level object.

    Basically, the higher the abstraction, the more layers I want between me and plain DBI. I end up with something like HLO -> ORM -> DBI. (HLO: High Level Objects). Of course, in most cases, the ORM doesn't use straight DBI either, so it's really HLO -> ORM -> SQLH -> DBI. (SQLH: SQL Helper, like SQL::Abstract and friends.) Why so many layers? Because I want some well-defined API at each level that I'm likely to reach down to. A gulf of non-public code between HLO and DBI is not to my liking. HLO -> SQLH -> DBI is better, but I still like that extra ORM layer because it's the one I work directly with most often.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2014-09-19 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (144 votes), past polls