hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.4K
active users

Jenniferplusplus

I don't understand why everyone hates ORMs so much. It makes no sense. For any non-trivial project, you are all but guaranteed to want one. Probably sooner than you think. Why not just use one from the beginning that you know to be robust and well understood, instead of half reinventing the whole concept, ad-hoc, one query at a time?

@jenniferplusplus it was felt that the ORM we were using was too much, and they wanted to go with something leaner. So yeah I had to map the relations myself. But I can also see what they're saying, Hibernate does feel like an enormous, impenetrable mystery wrapped in an API. I tried debugging it once when I needed to understand what it was doing 😬

@alter_kaker I can't speak to hibernate, but in entity framework, the actual query is just *right there* in my traces. And logs, if I set the log levels for it.

@jenniferplusplus I'm both going to need them and going to hate them. Because by their very name, they're a model and it's very hard in a long term project to see how it's going to be needed fully, so those changes in the future become painful (and no one wants to risk breaking everything).

This is most codebases! I might ask why we say this about ORMs more than other frameworks, etc? Something something optimizations maybe...

@gallego It's actually extremely fair to ask why we say this about ORMs more than other frameworks. Why is react or spring or aspnet a nearly automatic choice, but when you get to the database suddenly people can only tolerate hand-written sql?

@jenniferplusplus

@gallego
My biggest hangup is with ORMs that let you model joins. It abstracts away the complexity to a degree which makes it very easy to write extremely inefficient queries. But row->model mapping is essential to have in an application, in my opinion, and simple query generation is useful as well.

@wakingrufus Yeah, I'd agree with that. Anything more than two tables joined (and a relatively simple join) and you've lost the plot.

Sometimes relationships are complex with data! Models aren't sufficient. I'm ok with mixed ORM and raw SQL.

@jenniferplusplus
Half-serious comment:
Maybe because people intuitively know that OOP the way we are currently doing it is wrong?

@jenniferplusplus honestly, I just find them really heavy weight and obstructive to what I want to achieve. But then I spent years doing this before ORMs were in popular use, so I’m probably just used to doing it

@jenniferplusplus The main problem I had with SqlAlchemy is the fact it was poorly documented and I couldn't get it to work doing trivial stuff rather than any fundamental problem with ORMs.

@jenniferplusplus None of my day job stuff uses SQL databases - we have Cosmos, Azure File storage, http and message queues. Before that, AWS Dynamo and S3 with SNS/SQS.

Last job that used a SQL database as well, Dapper did all that we wanted, with minimal fuss. ORMS have never done that for me. We did not "reinvent" that heavyweight stuff.

@anthony_steele Dapper is an ORM, it's just light on features

@jenniferplusplus You can call Dapper an ORM if you want, I have heard it called a "Micro ORM".

It was near the right level of features and ceremony as far as I was concerned.

@jenniferplusplus we once had this conversation with someone who was like "cant i just write a loop around mysql_real_escape_string" and we were like "sure, and then youve just reimplemented a broken halfass version of something that an ORM is designed to handle correctly in the first place"

they kept on not using an ORM 🫠

@jenniferplusplus we wouldn't say hate, but we dislike them because, well, objects and relations aren't the same thing. they have different lifecycles, they have different performance characteristics, the nature of how identity works for them is different.

@jenniferplusplus the selling point of ORMs as opposed to the things we'd rather use is mostly that it lets the team include developers who only understand objects and not relations, but we would never want that, that's kind of the worst-case scenario even, because then we're guaranteed to get into problems the team can't get itself out of.

@jenniferplusplus we are all for high level frameworks that encapsulate queries, or even generate them, but those frameworks need to respect the fundamental nature of the data as relational.

@jenniferplusplus also, just to note this, ORMs go back a long way but there's an even more aggressive step that we think got introduced around the time of Rails, which is the idea that your underlying database should be object-shaped not relation-shaped because that speeds up development of user-facing stuff

@jenniferplusplus and, like, yeah, that probably does speed up application development, and if all you want to do is make an application and sell access to it, great, that may even be a reasonable approach. if your database exists to explore some important problem domain, though, it's inappropriately confining.

@jenniferplusplus anyway, as always with this stuff we are careful in how we talk about it. people are not synonymous with the tools they use and we don't think less of anyone for these choices, or for disagreeing with our analysis.

@jenniferplusplus it's important to respect each others' humanity even when there are differences of opinion. that too often gets forgotten in computing, so we say it explicitly

@ireneista My perspective is that I am, once again, watching someone re-invent an object-relational query builder. I've never been on an orm-free project backed by an RDBMS that didn't do this. It happens every single time.

@jenniferplusplus it's also one of those areas where people have a tendency to incorrectly feel that they can do better without actually having any new ideas

plus it's more fun to work on abstract problems than specific ones

@jenniferplusplus @ireneista yep. That part. Even the people who swear they hate them end up building a hacky, undocumented version of it.

I mean I feel like the right answer is way simpler than people want it to be. ORMs are useful. But they should not preclude you from being intentional about the structure of your underlying data. And you should always be able to bypass the abstraction if/when you need to.

@polotek @jenniferplusplus the ORMs we're okay with are the ones that don't get in our way when we care about the structure of the data, yes

@polotek @jenniferplusplus just to make sure we're on the same page, we've run into situations where no popular ORM in a given language allowed multi-column keys, and the developers viewed that as a weird curiosity nobody would care about

@polotek @jenniferplusplus that is not a deficiency in the concept of an ORM, but it's, as we said elsewhere in the replies, a detail-centric thing that people lack the vocabulary to talk about, and that the focus on objects as the most important abstraction tends to make it harder to deal with

@polotek @jenniferplusplus we would like to get to a world where all the pieces of this problem are well understood and easy to learn about. then the discussions might start going better.

@polotek @jenniferplusplus we also do think it's important to keep in mind that not every query builder is an ORM. query building is just one piece of the problem.

@ireneista @jenniferplusplus for sure. I don't think I would argue with anything you've said. Devs love to give away their agency to make things easier on themselves. That's the thing people often come to regret later.

This was my snarky way of saying ORMs are often attractive to people because they don't want to be bothered to learn the power available at their database layer. In fact they actively avoid it.
social.polotek.net/@polotek/11

social.polotek.netMarco Rogers (@polotek@social.polotek.net)@jenniferplusplus@hachyderm.io hot take. People don't actually hate ORMs. They hate databases. But they can't actually get rid of the latter. 😂

@polotek @jenniferplusplus oh ha yes, that's honestly a fair way to put it (in the quoted toot)

@ireneista @jenniferplusplus and that's very different from saying we want this abstraction for the 80% problems. But we can still fully utilize our database features for the other 20% problems.

I feel like we have to be careful with how we frame this critique. But there are lots of different types of engineers on teams. Some of them like abstractions because it means they don't have to think to hard about how to solve problems. They let the tools constrain their thinking.

@polotek @jenniferplusplus and like, in a sense that's the point of abstractions, yeah. if they don't save us trouble, why do we have them?

for us as a team leader though, we think it would be a mistake to let our reports avoid learning how databases work in the long run, even if it might make tactical sense as a very brief thing

@ireneista @jenniferplusplus I see it a little differently. I see the point of abstractions as enabling us greater leverage to build more complex solutions on top of powerful primitives. Humans can't handle complexity. We have to compartmentalize and abstract. But if we do that enough, we can build amazing things. But abstractions become net negative when they don't leverage all of the underlying primitives and instead start to constrain the solution space.

@ireneista @jenniferplusplus your example about multi-column keys is a good one. If the abstraction doesn't leverage the fact that the database has already solved this, then solving it at the application layer actually becomes harder and is much less efficient. And that's one of the experiences that can result in people generally disliking ORMs. In that case, they remember the abstraction made their lives harder. But it's important to dig into what actually happened.

@polotek @jenniferplusplus as regards the point of abstractions, we have some framing on another topic that we think also applies here. we think that encysting complexity is never sustainable, while engaging with it has a chance to be.

it's the job of a well designed abstraction to figure out what concerns won't go away, and need to be bubbled up

@polotek @jenniferplusplus constraining the solution space, we'd argue, CAN be okay in limited situations - for example, if the full complexity underneath is not relevant to the goals being accomplished. so we don't really think of it in terms of constraints personally, though we see the point

@ireneista @jenniferplusplus the ORMs we've used tend to work by building queries and then presenting you with a sequence of objects whose properties allow you to access their relationships, and it works well enough.

@atax1a @jenniferplusplus how much trouble it causes in practice really depends on a lot of details. some frameworks are much, much better than others and that all hinges on stuff that nobody even really has the vocabulary to talk about properly, let alone explain why one is good and one is bad

@atax1a @ireneista Sounds like they support a query object pattern, which I am an increasingly big fan of.

@jenniferplusplus @atax1a oh! yes. heh. we didn't have a word for that :) yes, we like that pattern. we note that it potentially hits limitations when you try to put an MVC thing in front of it, but we like it, so it's our view that the upper layers should change as needed to accommodate it.

@ireneista something I feel is severely lacking in programming languages is a way to define a Type Of Thing, with some Fields and some Operations We Can Do To The Thing, without necessarily assuming that we always want to load all the fields all the time

@Gaelan yes! absolutely

and it's...

we've seen people do this (because yes, like j++ we've seen people reinvent ORMs for their own projects) in a way where they lazy load the fields

and that turns out to be a really bad idea because it has a sharp performance cliff

@Gaelan what we'd be personally enthusiastic about is a formalism that captures the idea that this object is a slice of that one, and can be used in places that only need stuff from inside the slice

@Gaelan this can be done with type classes but it's arduous because you wind up needing one for each column

@ireneista typescript actually handles this pretty well I think! It lets you pass a {a: number, b: number} to anything that wants a {a: number}

@Gaelan oh right! structural types, we really need to spend more time with that.

@ireneista yep, and if you use something like kysely your query results come through with the appropriate types as well - which just leaves you with the annoying bookkeeping of listing the required fields in your function signatures and queries

(in my ideal language, the compiler would infer which fields were being read and generate the appropirate query that way, so the fact that you're not requiesting all the fields becomes more or less invisible - I'm not sure how viable that is!)

GitHubGitHub - kysely-org/kysely: A type-safe typescript SQL query builderA type-safe typescript SQL query builder. Contribute to kysely-org/kysely development by creating an account on GitHub.

@jenniferplusplus totally agree
They can be more obtuse and make it harder to optimize the underlying queries
But for most applications? Doubt that it matters all that much

@esg It rarely matters. And where it does matter, all of them let you eject from the mapper and hand write some sql.

@jenniferplusplus I wonder if there's leftover trauma being carried over
For example, ef core is so much easier to debug than ef ever was

@esg I'm sure that's part of it. Or, something like it.

@jenniferplusplus Do you have any ORMs you enjoy using? Currently dealing with issues related to handwritten SQL in a project and I'm not experienced enough to suggest fixes but I can feel the tech debt eating at the team.

@igimenezblb I just go with EF Core when it's up to me. Enjoy would be over stating things, but it's robust and extremely well documented. That's basically what I want out of most any framework.

@jenniferplusplus hot take. People don't actually hate ORMs. They hate databases. But they can't actually get rid of the latter. 😂

@jenniferplusplus @polotek

(I hate ORMs and like databases)
Nah, actually I hate that every time I've looked at using one, I've already done the DB design and the ORM just wants to fight me about it instead of being a nice wrapper that stays out of the way. Last time was a while ago now, so maybe it's not like that these days.

@jenniferplusplus @polotek which is just wild to me. Databases are like the lifeblood of my professional life!