News for hackers. Stuff that matters.
Re:Net 9.0 LINQ Performance Improvements by apwell23 on Friday October 18, 2024 @08:18AM (#41878702)
No it isn't easy to find similar capabitites in java, go, python, ruby.

Maybe you do simulate some of this using meta programming in ruby but its certainly not 'easy to find'.

Re:Net 9.0 LINQ Performance Improvements by svieira on Friday October 18, 2024 @09:37AM (#41879346)
There are easy ways to do some subset of what LINQ does in Java (using annotation processors), in Go (using generators), in Python (using double-underscore methods to capture all the operations the expression is working with at runtime, see SQLAlchemy) and in Ruby.

There isn't a seamless way to do what LINQ does in any of those languages. But if the runtime supports a LISP then you can do more than what LINQ does (Clojure for the JVM, something like zygomys for Go, Hy for Python, and ... well, Ruby for Ruby).

Re:Net 9.0 LINQ Performance Improvements by pjmlp on Friday October 18, 2024 @08:23AM (#41878746)
It certainly is, unless you are talking about SQL like syntax, which is basically syntax sugar for classical FP.

And I explicitly left Go out of my list.

Re:Net 9.0 LINQ Performance Improvements by apwell23 on Friday October 18, 2024 @08:42AM (#41878887)
>unless you are talking about SQL like syntax

yes thats what linq is?

https://learn.microsoft.com/en-us/dotnet/csharp/linq/

"Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language." With LINQ, a query is a first-class language construct, just like classes, methods, and events.

doing this in java is not LINQ imo

  List<Integer> lowNums = filter(toList(numbers), new 
  Predicate<Integer>() {
        @Override
        public boolean apply(Integer n) {
            return n < 5;
        }
    });
Re:Net 9.0 LINQ Performance Improvements by ygra on Friday October 18, 2024 @09:35AM (#41879328)
I guess the very fact that LINQ is so many things makes such discussions a bit annoying at times because everyone refers to a different set of features.

Is it the SQL-like query syntax? LINQ to objects? LINQ to SQL? Expression trees in general?

Expression trees and LINQ to SQL/EF/etc. are hard to find elsewhere. The query syntax often doesn't seem to be that big of a deal, especially since not all methods are available there, so pure query syntax often doesn't work anyway.

Re:Net 9.0 LINQ Performance Improvements by pjmlp on Friday October 18, 2024 @10:53AM (#41879995)
I discovered someone stuff in Java pre-history days.

Because I am feeling nice,

     Arrays.stream(new int[]{1, 2, 3, 4, 5, 6, 10, 23, 45}).filter(n -> n < 5).forEach(System.out::println)
Re:Net 9.0 LINQ Performance Improvements by svieira on Friday October 18, 2024 @09:25AM (#41879238)
These days it would be

    var lowNums = Arrays.stream(numbers).filter(n -> n < 5).toList();
2024's Java is also quite a bit better than 2013's Java.

Which still isn't as nice as LINQ, but this way we've painted the alternative in its best light, not in the light that makes C# look the best.

Re:Net 9.0 LINQ Performance Improvements by Rohansi on Friday October 18, 2024 @09:50AM (#41879467)
One of the unfortunate pieces missing from Java's streams is the ability to easily extend them with additional operators. In C# they are all extension methods for the IEnumerable interface so you can add your own methods into the chain but that's not possible in Java.
Re:Net 9.0 LINQ Performance Improvements by pjmlp on Friday October 18, 2024 @10:54AM (#41880005)
It is coming, it is called Gatherers, another approach, same result.
Re:Net 9.0 LINQ Performance Improvements by svieira on Friday October 18, 2024 @11:23AM (#41880273)
I'm a huge fan of Gatherers, lovely API!
Re:Net 9.0 LINQ Performance Improvements by Rohansi on Monday October 21, 2024 @09:03AM (#41903726)
Good that there's a solution coming up but it's not as nice as C# IMO. Gatherers are way more verbose both in usage and especially in implementation. In C# they can be written as generator methods which is a very intuitive way to work with streams of data.
Re:Net 9.0 LINQ Performance Improvements by apwell23 on Friday October 18, 2024 @11:35AM (#41880381)
i posted that example from a comment that linked to this repo https://github.com/mythz/clojure-linq-examples

my point was that laguange support for sql like sytax is part of what makes LINQ linq. Java niceties is not relevant.

Re:Net 9.0 LINQ Performance Improvements by SideburnsOfDoom on Friday October 18, 2024 @09:49AM (#41879460)
> yes thats what linq is?

The link that you gave says "LINQ is the name for a set of technologies" which includes the "SQL like syntax".

Includes is not the same as "is".

It isn't the most often used part of LINQ.

Re:Net 9.0 LINQ Performance Improvements by apwell23 on Friday October 18, 2024 @09:55AM (#41879503)
sure but you cannot just remove 'sql like syntax' and claim you can do linq in any language.
Re:Net 9.0 LINQ Performance Improvements by SideburnsOfDoom on Saturday October 19, 2024 @04:21AM (#41886462)
You can in fact ignore "sql like syntax" and find "similar capabilities" in many other languages. After all, most C# coders ignore the "SQL like syntax" in C# itself.

And when languages imitate features of a different language, they tend to go for the features that people like and use. No-one is going to add "similar capabilities" to the feature that no-one wants in the first place. People who say "C#'s LINQ is awesome!" just aren't talking about "sql like syntax", and people who say "without sql like syntax it's just not on the same level as LINQ" are misguided.

Re:Net 9.0 LINQ Performance Improvements by high_na_euv on Friday October 18, 2024 @09:12AM (#41879130)
To be fair, 99% of linq usage is method chaining syntax, not query syntax
Re:Net 9.0 LINQ Performance Improvements by apwell23 on Friday October 18, 2024 @09:31AM (#41879292)
LINQ = Language Integrated Query

Its even in the name. What do you mean by "method chaining is linq" ?

Re:Net 9.0 LINQ Performance Improvements by ygra on Friday October 18, 2024 @09:37AM (#41879342)
Considering the methods live in the System.Linq namespace, I think the extension methods may also be called LINQ.
Re:Net 9.0 LINQ Performance Improvements by high_na_euv on Friday October 18, 2024 @09:40AM (#41879380)
"var results = list.Where(x => x.Salary > 12345).Select(x => x.Name).ToList())"

Giant majority of ppl refers to this when talking about LINQ.

But yea, it is LINQ method chaining.

SQL like syntax is LINQ query syntax

Re:Net 9.0 LINQ Performance Improvements by apwell23 on Friday October 18, 2024 @09:54AM (#41879493)
> But yea, it is LINQ method chaining.

You mean like fluent interface? https://en.wikipedia.org/wiki/Fluent_interface

What does this have to do with LINQ or C#. I remember doing 'method chaining' in 1990s .

Re:Net 9.0 LINQ Performance Improvements by high_na_euv on Friday October 18, 2024 @09:57AM (#41879518)
>fluent interface

Various names, same concept.

"fluent interface is an object-oriented API whose design relies extensively on method chaining."

>What does this have to do with LINQ or C#.

Check the name of the namespace where all those APIs like Where, GroupBy, etc. are implemented, it is "System.Linq"

So thats why majority of ppl think about them when talking about LINQ.

Query syntax has like less than 1% of the "market share" versus method chaining style

Re:Net 9.0 LINQ Performance Improvements by Merad on Friday October 18, 2024 @04:01PM (#41882948)
LINQ is the name for the overall system. LINQ can be written using two different styles:

    // Method syntax
    var evenNumbers = numbers.Where(num => num % 2 == 0).OrderBy(n => n);

    // Query syntax
    var evenNumbers = from num in numbers
        where num % 2 == 0
        orderby num
        select num;
Method syntax and query syntax are both part of LINQ (query syntax is syntactic sugar). .Net developers tend to overwhelmingly prefer method syntax.