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.
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 onIAsyncEnumerable
, 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 anawait foreach
. In Rust, you get the same options (though more verbose) using streams fromfutures
.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.
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
I never had a issue with loops. If I feel something is off, I terminate, check code, and fix it.