EDIT: Unless you're often switching between relational databases, which is the perfect use case for an ORM.
EDIT EDIT: I guess the point I'm trying to make is that database query languages aren't scary. Learn them rather than and unlock their full power without constraints of a query builder or ORM.
Oof. This debate has been beaten like a dead horse.
My two cents: Database query languages aren't harder than any other programming language. ORMs may speed up writing simple things at first, but once you get to the nitty gritty, you'll find yourself using the escape hatch into the base query language anyway. You'll do other developers a favor by exposing the lower level queries and removing the extra unnecessary layer of abstraction.
Hm, I can see that. I guess I've always liked them since they're easier to read in the respective language, but maybe it's time to make a switch away from them.
Just another thing to add to my never-ending list to read about programming!
Honestly, if you're worried about having too much to learn, then I think you're doing yourself a disservice by learning an ORM. Yes it is in the same language that you're learning (say Javascript) but behind the scenes, javascript is transpiling how you used the ORM API to the query language. Why not just jump straight into the query language and unlock its full power?
The counter argument to this is that an ORM is supposed to abstract away the database details, so theoretically you could swap out your database with another one and you wouldn't need to change the code at all.
My experience in practice is that it never happens like this due to the vast differences in database structures. If you're switching from one relational database to another (MySQL to SQLite) or something like that, then okay, maybe. (What would be the benefit of doing this anyway?...)
But most of the time when you switch a database, you're looking to get some extra performance and cater to how your data is structured. So you're going from a relational database to a noSQL database, or to a graph database for example. In that case your ORM abstraction is gonna be completely useless and you're going to have to rewrite everything anyway.
I think that ORMs are the wrong abstraction.
My advice: If you can learn MySQL, you'll be able pick up on any other database query language that you need to just fine. If you get thrown into a codebase that uses an ORM, you'll be able to pick that up even quicker if necessary.
Well actually, I've been programming for about 9 years now, and I'm well versed in MySQL :) I'm more wondering about new hires, especially junior devs, I bring into a future company I'm in the midst of creating. I know when I was an intern, having everything laid out in an ORM was really beneficial to me. It meant I could understand everything from the get go without being bogged down by further training in MySQL.
Still, you definitely raise an interesting point. Maybe it's better to just train people in SQL? It is more versatile. I'm wondering if there's a balance between ease of use and "standards," but I guess that's more of a me issue haha.
Anyway!
If you're switching from one relational database to another (MySQL to SQLite) or something like that, then okay, maybe. (What would be the benefit of doing this anyway?
This is actually really interesting because I didn't even think of it. I do this all the time in my work! I create scripts for clients, and some clients want the script to be portable while others require web services. This means I'm constantly changing my boilerplates between using SQLite and MySQL, so maybe sticking with an ORM is important just for that use case! I'm glad you brought that up.
Thanks for taking the time for your response man. You have good points, appreciate it! I'm not sure if I'd say ORMs are "the wrong abstraction" for my uses, but switching my code base / boilerplates to queries is something I might consider down the road.
Edit: Also, if you are creating out the ORM, there's no way to do that without using SQL (in my experience). In my opinion, the practicality of an ORM is being immediately understandable for people who aren't creating it or just for yourself later on down the road.
4
u/libertarianets Dec 10 '19 edited Dec 10 '19
Stop using ORMs.
EDIT: Unless you're often switching between relational databases, which is the perfect use case for an ORM.
EDIT EDIT: I guess the point I'm trying to make is that database query languages aren't scary. Learn them rather than and unlock their full power without constraints of a query builder or ORM.