3 ms·
I've thought about this a bit, having had to write various ORM layers over the years. My conclusion is that OOP is conceptually built around single "objects" w
by sanj 19y ago
I've thought about this a bit, having had to write various ORM layers over the years.
My conclusion is that OOP is conceptually built around single "objects" where RDBMSs are built around sets of "objects". The difference in nominal units is some of the basis of the impedence mismatch.
Think about what it takes to do something interesting with a collection of objects in c++/java/whatever, such as pick out the subset that have a cost>n: it is a loop over the entire set. Ruby makes it prettier and cleaner, but you're still just looping. Unless you create a custom collection class that internally stores a hash organized by costs. But the creation of the new class is extra overhead because the nominal unit is the single object.
The counterexample is just as instructive. To retrieve the newest 10 entries in a blog uses the LIMIT syntax in SQL, which is painfully nonstandard: http://troels.arvin.dk/db/rdbms/#select-limit http://troels.arvin.dk/db/rdbms/#select-limit
Things that are simple in one space are hard in the other.
In my own work I've resolved some of this by attempting to avoid abusing the "standard" ORM tools that are out there that allow designing queries in your language of choice (Rails for Ruby, Hibernate for Java). Instead, I attempt to figure out exactly what I need out of query: how to structure the SQL to give me back the exact set of data I care about. No subsequent looping in Ruby/Java allowed.
That forces a line in the system between the DB and the application code where each is able to be use its nominal units in as native a way as possible.
- neilc 19y agoYou don't need to step outside the SQL standard to retrieve the newest 10 entries in a blog -- SQL window functions (RANK(), ROW_NUMBER()) can do this, and they're part of the spec. You could also use a cursor with ORDER BY.
- sanj 19y agoI don't believe that row_number() is standard, and I thought it couldn't be relied on for being monotonically increasing with inserts. It will also fail if you need to use a date column that may not be ordered by time. And, for me at least, cursors are definitely in the range of "advanced-ish" SQL. My point isn't that it can't be done -- empirically, many blogs do it -- but that it points to part of the impedance mismatch.
- neilc 19y ago> I don't believe that row_number() is standard Sure it is: see Section 6.10 of Part 2 of SQL:2003. > I thought it couldn't be relied on for being monotonically increasing with inserts. It will also fail if you need to use a date column that may not be ordered by time. I think you are confused: ROW_NUMBER() is a window function, and as such is applied to an arbitrary query expression: SELECT x, y, row_number() over (order by z) from t And I would beg to differ that cursors fall into "advanced-ish" SQL :) I don't see how it is an "impedance mismatch": transforming sets of data is the fundamental goal of SQL, and this seems to fall squarely within that domain.