this post was submitted on 03 Dec 2025
817 points (99.0% liked)

Programmer Humor

27635 readers
901 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Rusty@lemmy.ca 66 points 22 hours ago (2 children)

You can add SQL in the 70s. It was created to be human readable so business people could write sql queries themselves without programmers.

[–] ZILtoid1991@lemmy.world 19 points 19 hours ago (3 children)

So is COBOL.

(Is there any sane alternative to SQL?)

[–] Rooster326@programming.dev 1 points 9 hours ago

(Is there any sane alternative to SQL?)

Well there is our lord and savior, or so I'm told by many MBA(s), No SQL

Oh wait you said Sane. Nevermind.

[–] drasglaf@sh.itjust.works 9 points 19 hours ago (1 children)

(Is there any sane alternative to SQL?)

Yes, no SQL.

[–] marlowe221@lemmy.world 2 points 10 hours ago
[–] ChickenLadyLovesLife@lemmy.world 33 points 22 hours ago (3 children)

Ironically, one of the universal things I've noticed in programmers (myself included) is that newbie coders always go through a phase of thinking "why am I writing SQL? I'll write a set of classes to write the SQL for me!" resulting in a massively overcomplicated mess that is a hundred times harder to use (and maintain) than a simple SQL statement would be. The most hilarious example of this I ever saw was when I took over a young colleague's code base and found two classes named "OR.cs" and "AND.cs". All they did was take a String as a parameter, append " OR " or " AND " to it, and return it as the output. Very forward-thinking, in case the meanings of "OR" and "AND" were ever to change in future versions of SQL.

[–] merc@sh.itjust.works 2 points 8 hours ago

I did that myself back in the day. Not overly complicated, but a SQL builder.

I think it's because SQL is sort-of awkward. For basic uses you can take a SQL query string and substitute some parameters in that string. But, that one query isn't going to cover all your use cases. So, then you have at least 2 queries which are fairly similar but not similar enough that it makes sense just to do string substitutions. Two strings that are fairly similar but distinct suggests that you should refactor it. But, maybe you only make a very simple query builder. Then you have 5 queries and your query builder doesn't quite cover the latest version, so you refactor it again.

But, instead of creating a whole query builder, it's often better to have a lot of SQL repetition in the codebase. It looks ugly, but it's probably much more maintainable.

[–] jacksilver@lemmy.world 17 points 22 hours ago (4 children)

Object Relational Mapping can be helpful when dealing with larger codebases/complex databases for simply creating a more programmatic way of interacting with your data.

I can't say it is always worth it, nor does it always make things simpler, but it can help.

[–] ricecake@sh.itjust.works 3 points 9 hours ago

My standard for an orm is that if it's doing something wrong or I need to do something special that it's trivial to move it aside and either use plain SQL or it's SQL generator myself.

In production code, plain SQL strings are a concern for me since they're subject to the whole array of human errors and vulnerabilities.

Something like stmt = select(users).where(users.c.name == 'somename') is basically as flexible as the string, but it's not going to forget a quote or neglect to use SQL escaping or parametrize the query.

And sometimes you just need it to get out of the way because your query is reaaaaaal weird, although at that point a view you wrap with the orm might be better.

If you've done things right though, most of the time you'll be doing simple primary key lookups and joins with a few filters at most.

[–] nilloc@discuss.tchncs.de 6 points 13 hours ago

I used to use ORMs because they made switching between local dev DBs ( like SQLLite, or Postgres) and production DBs usually painless. Especially for Ruby/Sinatra/Rails since we were writing the model queries in another abstraction. It meant we didn’t have to think as much about joins and all that stuff. Until the performance went to shit and you had to work out why.

[–] trxxruraxvr@lemmy.world 10 points 20 hours ago (2 children)

I don't have a lot of experience with projects that use ORMs, but from what I've seen it's usually not worth it. They tend to make developers lazy and create things where every query fetches half the database when they only need one or two columns from a single row.

Yeah. Unless your data model is dead simple, you will end up not only needing to know this additional framework, but also how databases and SQL work to unfuck the inevitable problems.

[–] bort@sopuli.xyz 7 points 19 hours ago* (last edited 19 hours ago) (1 children)

the problem with ORM is that some people go all in on it and ignore pure SQL completely.

In reality ORM only works well for somewhat simple queries and structures, but at some times you will have to write your own queries in SQL. But then you have some bonus complexity, that comes from 2 different things filling the same niche. It's still worth it, but there is no free cake.

[–] elkien@lemmy.today 5 points 16 hours ago

I've always seen as that as a scapehatch for one of the most typical issues with ORMs, like the the N+1 problem, but I never fully bought it as a real solution.

Mainly because in large projects this gets abused (turns out none or little of the SQL has a companion test) and one of the most oversold benefits of ORMs (the possibility of "easily" refactor the model) goes away.

Since SQL is code and should be tested like any other code, I rather ditch the whole ORM thing and go SQL from the beginning. It may be annoying for simple queries but induces better habits.

[–] Clent@lemmy.dbzer0.com 0 points 20 hours ago

What part of this is irony?