News for hackers. Stuff that matters.
Re:Python: Just Write SQL by khazhoux on Monday August 14, 2023 @06:00AM (#37119220)
He didn't really. The SQL is right there, and this is important.

What I've experienced (unfortunately) across multiple projects is that people who understand databases will write SQL with a nice collection of helper and wrapper functions as needed, and the people that think that databases are mysterious black boxes will reach for ORM. I've seen the ORM-happy teams getting scared at the idea of a million (1,000,000!) rows in a table, and they always neglect to set up even basic indexes or to think through what their JOINs are really doing.

YMMV but that's the pattern I see again and again.

Re:Python: Just Write SQL by mickeyp on Monday August 14, 2023 @06:28AM (#37119391)
I have decades of experience with databases and I happily use ORMs.

You're conflating ORM with people who know nothing about databases. Why?

Re:Python: Just Write SQL by jbreckmckye on Monday August 14, 2023 @06:38AM (#37119438)
From my experience, ORMs allow folk who know nothing about databases to continue knowing nothing about databases
Re:Python: Just Write SQL by masklinn on Monday August 14, 2023 @06:58AM (#37119566)
And from my experience, forcing people who know nothing about databases to write SQL will not make them learn about databases, all you end up with is worse SQL and more injections.

Although the worse offenders by far are those which decide ORM = bad and bypass it at every opportunity.

Re:Python: Just Write SQL by jbreckmckye on Monday August 14, 2023 @09:01AM (#37120551)
That's fair, ORMs can be slow but they rule out a whole category of basic mistakes
Re:Python: Just Write SQL by tracker1 on Monday August 14, 2023 @01:09PM (#37123581)
And introduce plenty more. over-fetching, unindexed joins across many tables being two of the more common.
Re:Python: Just Write SQL by wnolens on Monday August 14, 2023 @07:21AM (#37119735)
Isn't that just a useful abstraction?
Re:Python: Just Write SQL by mickeyp on Monday August 14, 2023 @07:47AM (#37119920)
So let's ban ORMs because newbies don't know the entire toolchain. Yes, that will definitely solve it.

Why stop there? Let's ban RDBMS. If you can't contemplate a binary file structure and index strategy perfectly tailored to your application's needs ahead of using an RDBMS, why should we deign to let you use an abstraction layer with clever query planning and algorithms?

It's all too easy to morally 'ban' people from technology and gatekeep it behind wishy-washy nonsense like "ORMs are bad for beginners."

Re:Python: Just Write SQL by jbreckmckye on Monday August 14, 2023 @08:41AM (#37120370)
I'm not sure if you are trying to reply to a different thread, but this level of hyperbolic attack is unwarranted. I have said nothing about "morally banning" people from using databases.
Re:Python: Just Write SQL by jbreckmckye on Monday August 14, 2023 @09:00AM (#37120540)
(this was a flippant remark, if I could edit it I would reword it)
Re:Python: Just Write SQL by boxed on Monday August 14, 2023 @09:14AM (#37120669)
C allows people who can't build a CPU from NAND gates to do programming :P
Re:Python: Just Write SQL by felipetrz on Monday August 14, 2023 @10:22AM (#37121358)
NAND gates allow people who can't build transistors from self-mined ores to build CPUs.
Re:Python: Just Write SQL by ckdot2 on Monday August 14, 2023 @06:08AM (#37119282)
Well, the SQL is always somewhere. If you use an ORM library, even if you use ActiveRecord, you will find some SQL in it. In the end, it always translates to SQL. In the blogpost, the writer created a User Python object ("O"). A corresponding (R) database row will be mapped (M) to the object. That's basically ORM. Not as heavy as the usual libraries that support relationships etc, but still, ORM.
Re:Python: Just Write SQL by baq on Monday August 14, 2023 @06:11AM (#37119296)
sqlalchemy allows you to separate ORM from SQL and combine them when needed. the idea that 'ORM == you don't have to write SQL and/or you can't write SQL' is, please excuse my strong words here, wrong.

my biggest gripe with sqlalchemy is that sometimes I know what I need to write in SQL (have a working prototype usually) and have trouble mapping the concept to sqlalchemy.core constructs, but that's mostly inexperience.

Re:Python: Just Write SQL by bakugo on Monday August 14, 2023 @06:30AM (#37119399)
Good ORMs provide the best of both worlds. Basic tasks such as loading a single object from the database by ID and then writing it back after changes are made shouldn't require you to write any SQL, because everyone already knows what that SQL looks like, just let the ORM do it for you. A query builder component that allows you to programmatically build queries of medium complexity is also essential. And for anything not covered in the previous two cases, it should be possible to just write raw SQL or something like it without the ORM fighting you for it.

My preferred ORM is Doctrine and it provides all of these features. It has its own variant of SQL called DQL that lets you effectively write complex select queries as raw SQL with a bunch of object-specific conveniences built in, and get back an array of objects.

Re:Python: Just Write SQL by jamil7 on Monday August 14, 2023 @07:19AM (#37119714)
For this reason I really like GRDB for iOS, documentation is also excellent.