2 ms·
Java streams have some advantages over C# Linq. IMHO, there's a more fundamental concept that everybody seems to be missing, which is that general purpose prog
by jiggawatts 4y ago
Java streams have some advantages over C# Linq.
IMHO, there's a more fundamental concept that everybody seems to be missing, which is that general purpose programming languages somehow fail at general purpose queries across trival, in-memory data structures.
A random example I like to bring up is: Can your LINQ-equivalent efficiently and idiomatically calculate both the "min" and "max" of a list without enumerating it twice?
Imagine you're writing some abstract library that can take any IEnumerable as the input(s). Will it scan a 1TB database table twice because the idiomatic coding style is:
var min = somelist.min();
var max = somelist.max();
This is such as basic, trivial example, yet C#, Java, Kotlin, etc... languages just fall flat on their face. Meanwhile, in SQL, a 48-year-old query language:
SELECT min(...), max(...) FROM sometable
But this is just scratching the surface. Ideally, all LINQ-style data inputs should be treated as something like a B-Tree index. Something that can be "walked" (not just enumerated!) efficiently using prefixes, ranges, and similar conditionals. Multiple queries should be able share such as "walk" to minimise the cost of streaming data in from memory... or wherever. Data should be partitioned across CPU cores just as efficiently, and the query language should make this natural.
I'm yet to see a language that scratches this itch.
- kaba0 4y agoWell, you can calculate min and max simultaneously with a reduce, but I do get your general point.