3 ms·
ORMs are a bad idea in the first place: relations are a great way to organise your data, why would you want to sully that by converting to something object orie
by eru 2y ago
ORMs are a bad idea in the first place: relations are a great way to organise your data, why would you want to sully that by converting to something object oriented?
> Too often I come across Python projects that are hyped and when I dive into it I find it rather underwhelming to say it politely. Invariably it turns out that those people don´t know any other language than Python.
To give a nice counterexample: Python's hypothesis library is really great, and compares favourably to its Haskell inspiration of QuickCheck.
- jampekka 2y ago> ORMs are a bad idea in the first place: relations are a great way to organise your data, why would you want to sully that by converting to something object oriented? One big why is SQL. It's a horrible language/API but sadly practically all relational databases are SQL.
- sgarland 2y agoSo horrible that it’s been the standard for 50+ years. The relational model is great. Embrace it, because it isn’t going anywhere.
- jampekka 2y agoRelational model is good, SQL is not. They are not the same thing.
- sgarland 2y agoShort of academic languages like D, nothing faithfully implements the relational model. Some compromises are necessary to make it useful for practical applications, hence SQL.
- eru 2y agoHave you looked at Datalog recently? SQL has other warts, apart from not being completely relational.
- CraigJPerry 2y agoThis is the nail on the head. I’m really not a fan of ORMs, I don’t think they save any time because to use them in a safe way, you NEED to fully understand the SQL that will be run. There’s no shortcut from this and it’s plainly just an extra step. I’ve been bitten too many times but one ironic problem is that they’re so damned reliable. 99.999% of the time your use of an ORM will be just fine. It can be hard to argue against sometimes even though that 0.001 time can be an extinction level event for the company. So if you need to understand the SQL that will be run anyway and ORMs occasionally introduce disastrous behaviour, why persist with them? Well to start with the obvious, SQL is not panacea, you can still be bitten with non-deterministic behaviour when you hand craft every query in sql (e.g. when was the last time you updated stats on that relation - will the optimizer select an appropriate strategy?). But a stronger reason is that some harder queries just suck to write correctly in SQL. Maybe you’re working with some kind of tree or graph and need a recursive common table expression: Enjoy! It might be better in most cases to write such a query at a higher level of abstraction (ORM) and take advantage of the more productive testing facilities.
- eru 2y agoI agree that SQL ain't great. You can model relations in your language without using SQL. (You could have a mapper from your internal modelling of joins etc to how you talk to your database.) In eg Haskell that works really well, but other languages are also flexible enough.
- bal00ns 2y agoThey’re incredibly convenient. It allows smaller groups of people to accomplish more in a shorter amount of time by providing a standardized interface that does a great job of integrating with their existing environment. When translating database input and output into server-side representations, you have two options: build and maintain the process yourself or use a mature tool designed for that specific purpose in your server-side language. I strongly prefer the latter, as do many others. I find that most people critical of ORMs end up creating their own narrowly focused, weakly tested ORM-like database compatibility layers in their backend. These have caused more problems than ORMs ever have.
- eru 2y ago> When translating database input and output into server-side representations, [...] I'm saying that your server side representation could also be done as a relation. No need for object orientation. I don't have a problem with the M part of ORM, but with the O part. _If_ you are having different representations, than having an automated mapper between representations is good. Agreed, yes.
- reaanb2 2y agoA more appropriate name for ORMs would be "network data model to SQL mappers". They don't facilitate good OOP and oppose relational thinking and data management.