this post was submitted on 30 Apr 2025
20 points (91.7% liked)

Programming

19911 readers
123 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
20
The Innocent Loop (lackofimagination.org)
submitted 2 days ago by Aijan to c/programming
top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 1 day ago

Yeah, getting the whole table from the db and filtering it in the code is always a bad approach. Put the filter in the db query.

[–] [email protected] 2 points 1 day ago* (last edited 1 day ago) (1 children)

This seems to me more like a complaint about JS's functional methods on arrays being eager rather than a complaint about loops. All of this is solved in languages with iterators (or async iterators for a potentially better solution).

For example, in C#, .Where does nothing immediately on enumerable types, and on IAsyncEnumerable, you can go as far as streaming/chunking results from a DB into the enumerable and filtering off the DB asynchronously just by passing the enumerable into an await foreach. In Rust, you get the same options (though more verbose) using streams from futures.

Edit: the rest of the article doesn't really have much to do with loops, but these are all solved problems in C#, Rust, and I assume other languages too. Even Python has iterables, and you can configure your thread pools however you want to for concurrency.

[–] [email protected] 2 points 1 day ago

Even Java has streams and stuff. Course Java so it's kind of weird (iterators are mutable and internally iterate the collection/whatever lazily) streams are lazy and only go through all the operations, mapping, filtering ect when you collect the elements somehow (like rust). JS is wild lol

[–] Reptorian 2 points 1 day ago

I never had a issue with loops. If I feel something is off, I terminate, check code, and fix it.