Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like the general idea, but unless you're assuming some very clever language or even more clever ORM that fixes things implicitly, wouldn't

    email.bulkSend(generateReminderEmails(getExpiredUsers(db.getUsers(), fiveDaysFromNow)));
get all users and then filter out the few that will expire in 5 days, on a code level? That doesn't sound like it would scale




Often the answer to "some very clever language" is a lazy functional language like Haskell, where it's quite common to express problems naturally on infinite or near-infinite lists (of numbers, users, whatever...) in this way - and the language's lazy evaluation semantics effectively turning it into an efficient streaming data pipeline of sorts.

But even if not, the example from the article is just hypothetical. `db.getUsers()` could be something that just retrieves rather efficient `[UserEmail, ExpiryTime]` pairs, and then you'd have to have a pretty enormous user base for it to not scale (a couple of million string/date pairs in memory should be no problem).


Modern computers are fast enough that a lot of bad code won't outright break. That doesn't necessarily make it good code

I fixed a performance issue at some point where a missing index meant a scan of millions of rows every login. It worked, and could log in 3 people per second or so. It was still terrible code.


I think it's just a contrived example. They probably wanted to show more than a single thing composing in a very short post given it's from their Toilet series.

Replace it with `getUsers(filters)` or even a specialised function, and it starts making more sense.


(author here)

It's exactly this - I do regret using "db" a bit now after reading all of the comments here, as it's taken away focus from the main point. But yes, the post had to fit on a single page, and I needed to pick something that most engineers would be familiar with.


Kinda hints most people haven't used a good ORM, or if they have maybe just don't understand how it really works. Django looks similar to this and would have the same misunderstanding (User.objects.all()), except it actually returns a QuerySet object that would let getExpiredUsers() apply its own criteria and not actually run the query until something tries to read from the object. There's an example up above where someone shows SQLAlchemy doing the same thing.

I agree. They could have picked a better example. Just db.getUsers() alone should set off alarm bells as soon as you see it.

Irrelevant. The "bad" code does it too. It's talking about something specific and not "let's fix all the problems with this code".

If you write one method poorly so you select too much and filter in a for loop, you just have a bad method you can fix.

If you pick and recommend a pattern where filtering should happen separately from retrieving, all your code will be bad

Give a man a fish / teach a man to fish, but bad.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: