Live data from Hacker News

What ORMs have taught me: just learn SQL (2014)

wozniak.ca

31–40 of 654 posts

Re: What ORMs have taught me: just learn SQL (2014)

#31

For anything complex, definitely. For anything simple, eh. It also feels to me like he's talking about a specific ORM - I know ActiveRecord has it's fair share of issues, but from what I know of AR usage and implementation, it either doesn't do what he's (legitimately!) complaining about or does do it in the way he's suggesting.

I think he's talking about Hibernate.

Re: What ORMs have taught me: just learn SQL (2014)

#32
post #14

ORMs lure you in with a false sense of neat abstraction. They have nice intuitive examples on their home pages. But then you use them in the real world, doing gnarly queries, and you realize that doing anything powerful and fast in the ORM requires its own completely separate abstractions, which are often difficult for the uninitiated to follow. It's also often a big pain to debug the raw SQL that gets compiled after…

You don't use ORMs for gnarly queries -- that's not what they are for! They are for making manipulating the entities easier -- reading the data out of the database in a way that makes easy to modify. You can (and should) use them for simple queries. You have a list of entities you want to query and filter, that's going to be fine. Joins are fine. But if you're doing some complex analysis, an ORM is the wrong tool. Th…

If the argument is that it's the right tool for simple jobs, then by definition it won't save a lot of effort.

Re: What ORMs have taught me: just learn SQL (2014)

#33

My personal gripe about ORMs is that they have two main usage patterns, and each of them has major drawbacks. The first pattern, common in frameworks like Django, is to cram the business logic into the ORM instance objects. This creates a tight coupling between the two separate concerns (business logic and data persistence), and will cause problems as soon as the two structures deviate from each other. The second pat…

Totally agree on the first pattern.

For the second, I don't see how skipping the ORM avoids that duplication. Presumably you still need to map your database fields to object attributes.

Re: What ORMs have taught me: just learn SQL (2014)

#34
ORMs have taught me to not rely on ORMs for critical storage. I have one product that uses ruby DataMapper. With my particular product (embedded industrial equipment) it’s terrible. I have to constantly fight it to correct MySQL problems.

If they had just used basic sql it would be much easier to refactor.

Re: What ORMs have taught me: just learn SQL (2014)

#37
Each time I see someone complain about ORMs I remember Greenspun's tenth rule[1], which adapted to ORM would be:

"Any sufficiently complicated program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of a decent ORM."

ORMs are hard for a reason. Using an ORM doesn't mean you can't or shouldn't use plain SQL where the situation calls for it. You can mix and match perfectly fine.

[1] https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule Edit: typo.

Re: What ORMs have taught me: just learn SQL (2014)

#38
post #5

SQL just isn't composable. I know this article is old, but these days it's not black and white. In the space between ORM and raw SQL there are things like AREL which can save a ton of dev effort without the "impedance mismatch".

Can you elaborate? SQL queries compose just fine, it is just that most developers don't understand the relational part.

Re: What ORMs have taught me: just learn SQL (2014)

#39
post #32

Earlier quoted context omitted.

You don't use ORMs for gnarly queries -- that's not what they are for! They are for making manipulating the entities easier -- reading the data out of the database in a way that makes easy to modify. You can (and should) use them for simple queries. You have a list of entities you want to query and filter, that's going to be fine. Joins are fine. But if you're doing some complex analysis, an ORM is the wrong tool. Th…

If the argument is that it's the right tool for simple jobs, then by definition it won't save a lot of effort.

Just because a job is simple doesn't mean it doesn't take time & effort. A tool can be helpful if it reduces the time or effort to accomplish something.

Re: What ORMs have taught me: just learn SQL (2014)

#40
post #14

ORMs lure you in with a false sense of neat abstraction. They have nice intuitive examples on their home pages. But then you use them in the real world, doing gnarly queries, and you realize that doing anything powerful and fast in the ORM requires its own completely separate abstractions, which are often difficult for the uninitiated to follow. It's also often a big pain to debug the raw SQL that gets compiled after…

ORMs are a tool in the overall toolbox. Attempting to apply their usage to every facet of an application is, of course, ham-fisted.
Post reply on HN