logoalt Hacker News

tengbretsonyesterday at 5:09 PM10 repliesview on HN

I don't disagree with any of the major gripes people have with orms and I find SQL to be much cleaner in a lot of circumstances.

That being said, if orms didn't force you to explicitly define your domain models about 60% of developers would simply never do it. And you would see differently structured, ad-hoc interfaces defined all over the code base completely entangled with whatever action they are trying to perform.

ORMs being a forcing function for domain modeling is enough benefit for me that it outweighs all of their obvious limitations.


Replies

Kon5oleyesterday at 8:33 PM

>ORMs being a forcing function for domain modeling is enough benefit for me that it outweighs all of their obvious limitations.

That was a surprising take!

I know only a few ORM's but it seems they end up just adding another layer of DTO objects that are entirely separate from the domain classes anyway. So best case the ORM is just a detour for a good domain model. Worst case it creates a weird database-contaminated domain model that's hellish to maintain.

So I would't say ORMs force domain modeling, or even help. Are you perhaps thinking of a particular stack where the ORM is just one part of it?

show 3 replies
sandreasyesterday at 5:16 PM

Additionally I think the migration management that most ORMs support are also a good thing. Defined and type-safe forward and backward strategies are helpful in most cases, especially if you'd like to support more than one DBMS.

I personally think that ORMs are good for management and simple CRUD cases, QueryBuilders are good for managing more complex queries while still being secure / type-safe and for everything else a thin database abstraction layer for native SQL queries with parameters / prepared statements is still required especially for performance use cases.

show 1 reply
miohtamatoday at 6:38 AM

SQL is pretty shitty language to write modular, reusable and easy to read code.

show 3 replies
sdevonoesyesterday at 8:17 PM

I understand you mean “data” model instead? Perhaps for simple cruds, there’s no much point in differentiating between the data model and the domain model. For more complex scenarios, having orm concerns leak into the domain model is not nice

show 2 replies
frevibyesterday at 7:19 PM

You shouldn’t use ORM entities as domain models. The domain should not depend on anything from the integration layer (db entities, REST request/ response, etc).

Ideally models are generated from SQL schemas, which you map to domain models.

ibejoebyesterday at 5:54 PM

Wouldn't you consider defining the schema doing the domain modeling?

I think ORMs do too much. I want to control the querying, or, more precisely, I want to control the SQL that goes to the planner. The good ones largely do allow for this, but I can't think of one that has innate support for vendor-specific features.

What I do appreciate is that they handle the boilerplate like managing connections, preparing statements, setting parameter values, and mapping database types back to client types.

show 2 replies
ozgrakkurttoday at 5:00 AM

> if orms didn't force you to explicitly define your domain models about 60% of developers would simply never do it

This was never the experience I had. If anything, people tend to plan too much.

grumpletoday at 11:40 AM

I think you hit the nail on the head.

I’m thinking about what Rails would look like without activemodel and activerecord. Or even just without activerecord, where we had to write the same sql every time we wrote a model but introduce the opportunity for a dev to screw it up. Imagine starting on a legacy code base and all the models had subtle differences in how they query the db. They don’t have the established conventions around _id fields, polymorphism, the nice bits around joins, and instead you have to discover bugs where you did a join but the two models each have a field called “description”…

Kinranyyesterday at 5:13 PM

I'd rather take a mess of ad-hoc interfaces. Forcing people to do domain modeling does not go well.

show 1 reply
j45yesterday at 8:49 PM

Too often, the avoidance of learning SQL creates more work than learning SQL.

One example is starting with NOSQL and proceeding to learn how to make it into a relational database.