News for hackers. Stuff that matters.
Re:Is ORM still an anti-pattern? by mschuster91 on Tuesday June 27, 2023 @04:54PM (#36498500)
A point I'm missing is: without using an ORM (or however else you're calling your database interface) you will eventually end up writing and maintaining one yourself, at least for CRUD stuff, and it will be filled with weird bugs, edge cases and security holes.

> A common complaint about ORMs is that they break two of the SOLID rules. If you aren’t familiar with SOLID, it is an acronym for the principles that are taught in college classes about software design.

And that right here is the problem. Academia is teaching people stuff that makes sense in an academic environment where time, maintainability, money and effort aren't of a concern (as long as you have grant money, but that's not relevant here) - and that leads to a very nasty collision when fresh graduates enter the workforce. They're used to shaving yaks and reinvent wheels all day long in the quest for a "perfect" solution, and if the company doesn't have (enough and qualified) senior/lead developers to catch that, you end up with ... very interesting products, budget overruns and/or dumpster fires. Or a combination of all of them.

ETA: There's something that can go even worse: when stuff designed by and for academics enters public availability. The best/worst example for that is OpenStack... enough knobs and twists to support the specialized environment of CERN and probably hundreds of universities worldwide, with components modularized to an insane degree, but almost impossible to get started with because it's so byzantine.

Re:Is ORM still an anti-pattern? by 082349872349872 on Tuesday June 27, 2023 @05:09PM (#36498716)
> you will eventually end up writing and maintaining one yourself

Only if you insist on formulating your logic based on "objects" instead of "rows"; see https://news.ycombinator.com/item?id=36498583

Re:Is ORM still an anti-pattern? by mschuster91 on Tuesday June 27, 2023 @05:15PM (#36498779)
Most programming languages have long since gone towards OOP so it is only natural for people to think of their database in the same way (which coincicentally is the same reason why MongoDB got so popular).

The key thing is: most applications won't ever reach the scale where it's a better investment to ditch the ORM and most of your data model than to increase the "instance-class" parameter of your RDS database. So many projects fail because they think from the beginning what life would be as a unicorn and burn all their money on an insanely complex tech stack that could have been S3 buckets for the frontend, a couple of EC2 servers for the backend and RDS for the database. The really basic stuff can get you really far without exposing you to vendor-lock in or yak shavings.

Shave the yaks when you actually need the fur.

Re:Is ORM still an anti-pattern? by doctor_eval on Tuesday June 27, 2023 @07:49PM (#36500350)
> most applications won't ever reach the scale where it's a better investment to ditch the ORM

Aside from working in a large application that used ORM (and had many, many problems because of it), my personal experience with using them - specifically Hibernate - to develop an application from scratch was based on a relatively simple application to parse and help reconcile bank statements. This was never going to be an application that required "scale".

What I found was that, relative to just using SQL, the ORM version of my application was much more complex, required significantly more knowledge of the tools, and produced inferior code.

While I was able to get an MVP up and running slightly faster with the ORM, the productivity benefits diminished - and rapidly became negative - while the performance of the application for even a single user was very poor. Eventually, what should have taken milliseconds in SQL was literally taking seconds in the ORM. Not only did it generate stupid queries, each query had much greater latency. And what I was doing was extremely simple.

In addition to the poor performance and greater complexity, ORMs - like all dependencies - are not cost-free. There can be a significant learning curve just to get started with an ORM like Hibernate, and that learning curve then needs to apply to all developers who touch the code base.

In our larger application, we found that hibernate specifically had so many edge cases - not to mention its own SQL syntax - that the overhead of using it came to dominate the development time for new features. The need to create multiple objects (database entities AND entity objects) that could get out of sync, problems with cache consistency, latency, HQL... the list of gotchas and principle violations (DRY, KISS, SRP) was endless.

These days I simply refuse to use ORMs, and tend to do any complex database work in the database itself, i.e. with plpgsql. I find working directly with SQL to be insanely productive, and the resulting code to be in the order of 10x - 100x faster than what I used to be able to achieve in Java using ORMs.

> The really basic stuff can get you really far without exposing you to vendor-lock in or yak shavings

In my experience, vendor lock-in and yak-shaving are exactly what you get with ORMs.

Re:Is ORM still an anti-pattern? by erik_seaberg on Tuesday June 27, 2023 @04:58PM (#36498556)
This. Use a good one unless you want to own half of a poor one.
Re:Is ORM still an anti-pattern? by wredue on Tuesday June 27, 2023 @07:37PM (#36500230)
This is just a claim that everyone who advocates for ORMs makes, but it’s not reality.
Re:Is ORM still an anti-pattern? by erik_seaberg on Wednesday June 28, 2023 @12:13AM (#36502193)
The third time I have to figure out whether to write obj.setCreatedAt(rs.getTimestamp("created_at", calendar)) or obj.setCreatedAt(rs.getLong("created_at")) I'm going to write code to look at the schema and the setter and figure it out automatically. And that’s where new ORMs come from.
Re:Is ORM still an anti-pattern? by isbvhodnvemrwvn on Wednesday June 28, 2023 @03:15AM (#36503366)
Query builders solve those problems without the complexity of ORMs.
Re:Is ORM still an anti-pattern? by mschuster91 on Wednesday June 28, 2023 @07:02AM (#36504788)
Query builders tend to get tediously verbose compared to a plain old `$entityManager->persist($object)`
Re:Is ORM still an anti-pattern? by treeman79 on Tuesday June 27, 2023 @05:03PM (#36498631)
Since a few departments and multiple companies struggle / fail because a super brilliant guy(s) was chasing perfection. No useful work could get done. Or it took 20-100x longer than a quick and dirty approach.

Perhaps the worst was when a team of highly skilled HTML designers were forced to learning functional programming. Sure the back end wizard to configure some setting was a marvel of modern engineering and elegant design. It just took 10 people a year to build.

VC money makes people weird.

Re:Is ORM still an anti-pattern? by pravus on Tuesday June 27, 2023 @08:00PM (#36500444)
> A point I'm missing is: without using an ORM (or however else you're calling your database interface) you will eventually end up writing and maintaining one yourself, at least for CRUD stuff, and it will be filled with weird bugs, edge cases and security holes.

The middle ground I've found is to use code generation for the CRUD boilerplate with a framework that makes it easy to do free-form SQL or easy query building. It gets rid of all the unnecessary contortions for advanced queries while still giving you a nice API for all the basic stuff because you get helpers instead of abstract objects. An example would be sqlboiler for Go.

Re:Is ORM still an anti-pattern? by invalidname on Tuesday June 27, 2023 @10:49PM (#36501675)
Yes!

This entire thread is filled with people complaining about ORM not matching vendor promises which is true.

* It won't let you swap a database with no effort * It won't remove the need to learn and understand the SQL it generates * It won't make schemas seamless

We use it since it's a standard abstraction that we would need to replicate otherwise. It makes caching the database access possible which is remarkably difficult to do at scale for manual SQL.

It comes with standardized tools and best practices that make issues like n+1 irrelevant.

The main problem with ORM are:

* Misaligned expectations * Bad ORMs

All you need to do to appreciate ORM is open a project written without it and try to change ANYTHING in that project... ORMs are amazing!

Re:Is ORM still an anti-pattern? by koromak on Wednesday June 28, 2023 @05:34PM (#36512912)
We heard so much negativity about SQLAlchemy that we decided to make our own lightweight query builder instead. 8 months later, and we're using SQLAlchemy...

The SQL language is wildly complex. It is seriously not trivial to make a fully featured query builder. Forget the actual 'relational mapping' part.