←back to thread

873 points belter | 2 comments | | HN request time: 0.433s | source
Show context
imjonse ◴[] No.42947407[source]
> ORMs are the devil in all languages and all implementations. Just write the damn SQL

It depends on what you're writing. I've seen enough projects writing raw SQL because of aversion to ORMs being bogged down in reinventing a lot of what ORMs offer. Like with other choices it is too often a premature optimization (for perf or DX) and a sign of prioritizing a sense of craftsmanship at the expense of the deliverables and the sanity of other team members.

replies(8): >>42947752 #>>42947978 #>>42948317 #>>42948504 #>>42953164 #>>42954817 #>>42956074 #>>42956308 #
qaq ◴[] No.42947752[source]
It's not so much optimization but experience that on any sufficiently large project you gonna run into ORM limitation and end up with mix of ORM and direct queries. So might as well...
replies(2): >>42948245 #>>42954198 #
The_Colonel ◴[] No.42948245[source]
Starting with raw SQL is fun. But at some point you find out you need some caching here, then there, then you have a bunch of custom disconnected caches having bugs with invalidation. Then you need lazy loading and fetch graphs. Step by step you'll build your own (shitty) ORM.

Same thing for people claiming they don't need any frameworks.

replies(4): >>42948519 #>>42950241 #>>42951262 #>>42953407 #
1. qaq ◴[] No.42950241[source]
caching is orthogonal to using or not using ORM. You might opt to have caching with or without ORM in a consistent manner. You can also opt to add read replicas fronted by say pgcat in Postgres case without having separate caching layer.
replies(1): >>42950714 #
2. The_Colonel ◴[] No.42950714[source]
I guess this is a point where terminology matters. If you work with SQL database in an OOP language, you pretty much always do some object-relational mapping, no matter if you have a big framework or just raw SQL connection.

But this is not what people usually call as ORMs. All the "bad kind of ORM" (JPA impls, Entity Framework, SQLAlchemy, Doctrine, Active Record...) have some concept of an entity session which is tracking the entities being processed. To me, this is a central feature of an ORM, one of its major benefits. It is, incidentally, also serving as a transaction-scoped cache.

I won't of course dispute that you can have caching on other levels as well (which may perform differently, for different use cases).