3 ms·
So, I'm typically not a lover of ORMs as they're typically implemented, and tend to also favor doing something close to the sproc-based method that Philip-J-Fry
by mumblemumble 6y ago
So, I'm typically not a lover of ORMs as they're typically implemented, and tend to also favor doing something close to the sproc-based method that Philip-J-Fry proposes in another comment.
It's always struck me as odd that, as a profession, we generally agree with, and can be quite fanatical about, the idea that different modules and services should try to hide their implementation details as much as possible, and instead speak over well-defined, constrained protocols such as APIs or interfaces; but as soon as an SQL database comes into the mix, we happily throw all that hard-earned discipline out the window and go back to directly swizzling the internal state of external collaborators.
That said, there are some use cases where I'm not sure how you get around something like an ORM. One is when you need to allow users to execute arbitrary searches against the data. If that's your situation, then, any way you cut it, you're going to end up with some system that takes an abstract representation of a query and compiles it to SQL. The only question is if you want to use something off-the-shelf to do it, or if you'd rather hack it together yourself. In my experience, there are few things on this earth that present a greater maintenance burden than a homegrown ORM-type library does once the original author has moved on to other things.
And there are others where avoiding an ORM is over-engineering. If your database is just an honest entity store, and you're just doing fairly straightforward CRUD operations against it, and it belongs to a single application, go ahead and punch the easy button and have a happy life.
- gwbas1c 6y ago> different modules and services should try to hide their implementation details as much as possible > but as soon as an SQL database comes into the mix, we happily throw all that hard-earned discipline out the window The data belongs to the database, not to whatever program you happen to work on at the moment. IMO, the impedance mismatch situation is a result of poor programming language design. Saying that the database abstraction "leaks" into your code is backwards; the shortcomings of your programming language "leak" into how you're handling your data.
- mumblemumble 6y agoI tend to blame the impedance mismatch more on the popularity of "entities" as a way of doing domain modeling in object-oriented programming. It's far from the only way to do domain modeling in an object-oriented language. It's not necessarily even a particularly good way, and it creates problems even if your app comes nowhere near a database.
- DownGoat 6y agoFor me the usefulness of a ORM depends a lot on the language I'm working with. In the .NET world the choice is easy, Linq and EntityFramework is a killer combination. It's so much faster, and better than writing your own queries. I don't feel any of the normal arguments I hear against ORM's apply to the Linq + EF combo. For Python and JS, I kinda can releate to some of the common arguments, but still feel that ORM's have a use.