News for hackers. Stuff that matters.
Re:How not to structure database-backed web apps: performanc... by grey-area on Thursday June 28, 2018 @03:55AM (#17414921)
I use an ORM. I don't perform queries like that because the ORM makes it easy to build complex queries, joins, limiting the data returned etc, then execute them in one query, it's a convenience, not a straightjacket.

The problem is not ORMs, the problem is just people not thinking about the resources their query over some data takes, and trying to do things in memory that are better done in the database (as in your example), because databases are hard, and sql is not a particularly friendly language, so they take the easy way out. They'd do things like iterating over all instances just as much if not using a framework/ORM, because they understand their programming language and don't care to understand SQL, and also because they get away with it when there are 1000 cars in the fleet, and didn't anticipate having 1 million.

Re:How not to structure database-backed web apps: performanc... by strken on Thursday June 28, 2018 @04:40AM (#17415113)
One of the biggest problems with ActiveRecord (the ORM in the article) is that it uses extremely obtuse names for extremely common methods. There are three different methods for finding how many things meet a given criteria[0], and none of them do the same thing. There are three different methods for loading data from an associated table[1], and none of them do the same thing either. None of the method names explain how the function is implemented or whether it's going to hit the database.

This is a problem that goes beyond the usual ORM antipatterns and bad database designs and becomes its own special kind of hell, because it makes code far harder to reason about and thus far harder to review, in a way that I don't remember encountering in Hibernate, Gorm, or anything else.

[0] count, length, and size

[1] includes, preload, and eager_load

Re:How not to structure database-backed web apps: performanc... by AsyncAwait on Thursday June 28, 2018 @06:27AM (#17415617)
This is mostly due to its popularity and various people needing different use cases, the long-time maintainer is now working on a mach cleaner ORM for Rust, called Diesel[1].

1 - http://diesel.rs

Re:How not to structure database-backed web apps: performanc... by mullsork on Thursday June 28, 2018 @08:16AM (#17416220)
Compile time SQL query checks... amazing! I've been trying to find a similar library for a while. Thanks for linking
Re:How not to structure database-backed web apps: performanc... by matwood on Thursday June 28, 2018 @09:17AM (#17416587)
jOOQ for Java does something similar. It's so good, I'm likely stuck with Java on the backend until I stop using RDBMs.
Re:How not to structure database-backed web apps: performanc... by lukaseder on Thursday June 28, 2018 @05:23PM (#17420590)
Hey Mat, thanks for spreading the love. Hope you never stop using RDBMS!

Fancy a couple of jOOQ stickers? :)

Re:How not to structure database-backed web apps: performanc... by matwood on Friday June 29, 2018 @09:14AM (#17424262)
I wouldn't use the stickers, so they would be wasted. Just keep making jOOQ a great to use library. :)

And while I have you here...your blog posts are always great and very informative. It's interesting to see the differences between RDBMSs (I really only have experience with MSSQL/MYSQL some PG), and how they do one thing or another.

Re:How not to structure database-backed web apps: performanc... by lukaseder on Friday June 29, 2018 @01:35PM (#17426070)
> Just keep making jOOQ a great to use library. :)

Will do! Thanks for the nice words about the blog.

Re:How not to structure database-backed web apps: performanc... by acdha on Thursday June 28, 2018 @08:25AM (#17416269)
> This is a problem that goes beyond the usual ORM antipatterns and bad database designs and becomes its own special kind of hell, because it makes code far harder to reason about and thus far harder to review, in a way that I don't remember encountering in Hibernate, Gorm, or anything else.

I feel like this brings up an annoying cultural problem in tech wgere developers hit intermediate skill levels and feel the need to proclaim their expertise by writing something in the you’re-doing-it-wrong genre but don’t have the breadth of experience to realize that they’re over-generalizing and so they go from “ActiveRecord has this problem” to “ORMs are bad” without asking whether anyone else has it better. I’ve read tons of similar posts where e.g. Java proved that exceptions, OOP, or static typing were bad or Twitter proved you shouldn’t use Rails.

Re:How not to structure database-backed web apps: performanc... by grey-area on Thursday June 28, 2018 @04:49AM (#17415149)
Yes there are a few problems with ActiveRecord; it has been well used and has accreted lots of similar functions (a victim of its own success), and also it doesn't make it crystal clear when you are hitting the database.

IMO ORMs should be simple, unsurprising, and only have one or two methods which actually execute the sql and fetch data - they are there to make it simpler to build queries and map rows to objects, not to blur the line between fetching and manipulating data.

Re:How not to structure database-backed web apps: performanc... by Nokinside on Thursday June 28, 2018 @05:14AM (#17415272)
Few months back I was working together with a group of framework programmers from a large consulting company.

They seem to spend solid third of their time googling for how to write a code. Write code, hit a jam, google, find something in stackoverflow, ruminate between what is found, copy paste and try if it works. They don't know their framework well enough to just write a code.

I'm a more of a embedded software/hardware guy and manager, but I can sit down and write pivot pivot query in plain sql without consulting any references.

I'm not saying these guys are doing something wrong. It may be that in the typical consultant work where you have existing old frameworks, new frameworks and new stuff coming in constantly, there is less value to master the tools that you are using. You write some glue, then move on.

Re:How not to structure database-backed web apps: performanc... by bodas on Thursday June 28, 2018 @05:37AM (#17415385)
That's a good thing, I think. Programmers should have a good understanding of general algorithms but it's up to the frameworks themselves to reduce the need to be "mastered". I don't want to spend time mastering a particular framework because that knowledge is not portable across languages.
Re:How not to structure database-backed web apps: performanc... by Nokinside on Thursday June 28, 2018 @06:09AM (#17415541)
I suspect it's good thing also. It may also be the only way to scale programming into larger groups.

You can differentiate the workforce. Programming by copy pasting example code withing frameworks may allow skipping the requirement to understand general algorithms.

Less required expertise means less pay and cheaper products. You hire 10 low-paid easily replaceable code monkeys who slap together pieces of software from ready components. It's like like assembly work. Then you hire one guy who knows things to supervise them and solve the problems when they can't figure them out. It's like blue collar assembly workers and engineers.

Re:How not to structure database-backed web apps: performanc... by cleong on Thursday June 28, 2018 @11:45AM (#17417855)
I think part of this is the industry and part of it is the technology. Entire languages in the web are basically meant to be glue. Embedded usually has different requirements from Web, memory and performance are real problems you run into fast if you don't know what your doing. Where in web, memory and performance are a problem of economics, everyone is being served from a cluster that can be scaled if the software is shoddy.