News for hackers. Stuff that matters.
Re:Taming the beast that is the Django ORM – An introduction by exceptione on Sunday September 01, 2024 @05:59AM (#41415596)
There is one part in me that says to not destroy your positive mood, there is another part in me that wishes to yell at the pythonistas in general to look outside the Python world.

Too often I come across Python projects that are hyped and when I dive into it I find it rather underwhelming to say it politely. Invariably it turns out that those people don´t know any other language than Python.

I see that as a general problem; Python is the language for beginners this day with an endless amount of tutorials, but it seems lots of those starters don´t get to have a look outside the Python world. I fear this is getting an even bigger problem because AI models are trained on a vast range of Python, not because it is better, but simply because it is the PHP of these days.

I don´t mean to imply that I know you have that "narrow profile".

I agree that the value in Python is for quick prototypes in case you know Python well. Outside of that (at the risk of a language war), I think one does better look into modern .net core or the JVM for a general purpose, high quality and highly efficient language/platform.

On the topic of ORM I think EF Core (.net core) and Doctrine (php) is strictly better.

Re:Taming the beast that is the Django ORM – An introduction by jampekka on Sunday September 01, 2024 @06:30AM (#41415724)
For pythonistas reading this: JVM and .NET frameworks are better for large projects in the sense that they turn even the simplest projects into large messes of pointless byzantine buggy architecture, which in some circles is a sign of "high quality".

Edit: That said, learning multiple programming languages (paradigms) is a very good idea. A reasonable dose of e.g. Java, .NET or C++ for example is great for understanding how programming languages and software should not be written. Learning modern JavaScript makes it obvious how Python really suffers from weak functional programming support, very bad performance and a horrible packaging system.

Re:Taming the beast that is the Django ORM – An introduction by DarkNova6 on Sunday September 01, 2024 @07:19AM (#41415950)
> For pythonistas reading this: JVM and .NET frameworks are better for large projects in the sense that they turn even the simplest projects into large messes of pointless byzantine buggy architecture, which in some circles is a sign of "high quality".

You got to back up this claim. The technologies you mentioned are entirely orthogonal to the architecture you are using.

Re:Taming the beast that is the Django ORM – An introduction by jampekka on Sunday September 01, 2024 @07:32AM (#41416031)
Re:Taming the beast that is the Django ORM – An introduction by DarkNova6 on Sunday September 01, 2024 @01:47PM (#41418771)
This is not even a counter argument. We are talking ORMs here, not dependency injection frameworks.

The Java equivalent to Django ORM would be Hibernate.

It doesn't strike me that you know what Spring does, nor where its own features end.

Re:Taming the beast that is the Django ORM – An introduction by jampekka on Sunday September 01, 2024 @04:52PM (#41420302)
The comment I replied to was to general development. And Spring is the most popular Java web framework (that it's called a "dependency injection framework" is kinda telling about the architectural ideology).

I've had the misfortune to use both Spring and Hibernate professionally.

Re:Taming the beast that is the Django ORM – An introduction by za3faran on Tuesday September 03, 2024 @01:48AM (#41431684)
I used Java, python, and golang professionally, and the Java ecosystem (and yes, including the language) is far ahead of what the others offer on almost all important fronts, including readability, expressiveness, testability, introspection, etc. You just need to be a little bit disciplined - then again, that is always the case regardless of language/platform.
Re:Taming the beast that is the Django ORM – An introduction by eru on Sunday September 01, 2024 @06:44AM (#41415794)
ORMs are a bad idea in the first place: relations are a great way to organise your data, why would you want to sully that by converting to something object oriented?

> Too often I come across Python projects that are hyped and when I dive into it I find it rather underwhelming to say it politely. Invariably it turns out that those people don´t know any other language than Python.

To give a nice counterexample: Python's hypothesis library is really great, and compares favourably to its Haskell inspiration of QuickCheck.

Re:Taming the beast that is the Django ORM – An introduction by jampekka on Sunday September 01, 2024 @07:10AM (#41415910)
> ORMs are a bad idea in the first place: relations are a great way to organise your data, why would you want to sully that by converting to something object oriented?

One big why is SQL. It's a horrible language/API but sadly practically all relational databases are SQL.

Re:Taming the beast that is the Django ORM – An introduction by sgarland on Sunday September 01, 2024 @08:08AM (#41416277)
So horrible that it’s been the standard for 50+ years.

The relational model is great. Embrace it, because it isn’t going anywhere.

Re:Taming the beast that is the Django ORM – An introduction by jampekka on Sunday September 01, 2024 @08:15AM (#41416334)
Relational model is good, SQL is not. They are not the same thing.
Re:Taming the beast that is the Django ORM – An introduction by sgarland on Sunday September 01, 2024 @12:05PM (#41417994)
Short of academic languages like D, nothing faithfully implements the relational model. Some compromises are necessary to make it useful for practical applications, hence SQL.
Re:Taming the beast that is the Django ORM – An introduction by eru on Sunday September 01, 2024 @12:08PM (#41418017)
Have you looked at Datalog recently?

SQL has other warts, apart from not being completely relational.

Re:Taming the beast that is the Django ORM – An introduction by CraigJPerry on Sunday September 01, 2024 @10:21AM (#41417179)
This is the nail on the head.

I’m really not a fan of ORMs, I don’t think they save any time because to use them in a safe way, you NEED to fully understand the SQL that will be run. There’s no shortcut from this and it’s plainly just an extra step.

I’ve been bitten too many times but one ironic problem is that they’re so damned reliable. 99.999% of the time your use of an ORM will be just fine. It can be hard to argue against sometimes even though that 0.001 time can be an extinction level event for the company.

So if you need to understand the SQL that will be run anyway and ORMs occasionally introduce disastrous behaviour, why persist with them?

Well to start with the obvious, SQL is not panacea, you can still be bitten with non-deterministic behaviour when you hand craft every query in sql (e.g. when was the last time you updated stats on that relation - will the optimizer select an appropriate strategy?).

But a stronger reason is that some harder queries just suck to write correctly in SQL. Maybe you’re working with some kind of tree or graph and need a recursive common table expression: Enjoy! It might be better in most cases to write such a query at a higher level of abstraction (ORM) and take advantage of the more productive testing facilities.

Re:Taming the beast that is the Django ORM – An introduction by eru on Sunday September 01, 2024 @12:07PM (#41418008)
I agree that SQL ain't great.

You can model relations in your language without using SQL. (You could have a mapper from your internal modelling of joins etc to how you talk to your database.)

In eg Haskell that works really well, but other languages are also flexible enough.

Re:Taming the beast that is the Django ORM – An introduction by bal00ns on Sunday September 01, 2024 @03:59PM (#41419860)
They’re incredibly convenient. It allows smaller groups of people to accomplish more in a shorter amount of time by providing a standardized interface that does a great job of integrating with their existing environment. When translating database input and output into server-side representations, you have two options: build and maintain the process yourself or use a mature tool designed for that specific purpose in your server-side language. I strongly prefer the latter, as do many others. I find that most people critical of ORMs end up creating their own narrowly focused, weakly tested ORM-like database compatibility layers in their backend. These have caused more problems than ORMs ever have.
Re:Taming the beast that is the Django ORM – An introduction by eru on Sunday September 01, 2024 @08:26PM (#41421477)
> When translating database input and output into server-side representations, [...]

I'm saying that your server side representation could also be done as a relation. No need for object orientation. I don't have a problem with the M part of ORM, but with the O part.

_If_ you are having different representations, than having an automated mapper between representations is good. Agreed, yes.

Re:Taming the beast that is the Django ORM – An introduction by reaanb2 on Thursday September 05, 2024 @05:44PM (#41460642)
A more appropriate name for ORMs would be "network data model to SQL mappers". They don't facilitate good OOP and oppose relational thinking and data management.
Re:Taming the beast that is the Django ORM – An introduction by itsoktocry on Sunday September 01, 2024 @07:16AM (#41415940)
Wow, I didn't think people still thought like this in 2024.

The widespread use of Python is a problem? People should learn java? Okay.

I'll note you don't talk about the usefulness of the projects themselves, only your opinion of what the code "looks like".

Re:Taming the beast that is the Django ORM – An introduction by juahan on Sunday September 01, 2024 @06:21AM (#41415686)
How are those better?
Re:Taming the beast that is the Django ORM – An introduction by greenchair on Sunday September 01, 2024 @06:40AM (#41415774)
job security for one big one
Re:Taming the beast that is the Django ORM – An introduction by za3faran on Tuesday September 03, 2024 @01:52AM (#41431705)
Statically typed languages, performance, refactorability, instrospection, debuggability, observability, the list goes on.
Re:Taming the beast that is the Django ORM – An introduction by greenie_beans on Sunday September 01, 2024 @08:57AM (#41416637)
no, i'm not about to go back to .net core