Most active commenters
  • mythz(4)
  • megadal(3)
  • pjmlp(3)

←back to thread

201 points olvy0 | 12 comments | | HN request time: 1.121s | source | bottom
Show context
high_na_euv ◴[] No.41878416[source]
LINQ is so fucking useful and well designed feature of .NET ecosystem that it is unreal when you gotta use lang which doesnt have such a thing.

C# design team is/was unparalleled

replies(7): >>41878459 #>>41878543 #>>41878588 #>>41878686 #>>41879163 #>>41879194 #>>41879315 #
pjmlp ◴[] No.41878459[source]
LINQ is largely based on FP stuff, also how Smalltalk collections work.

It is relatively easy to find similar capabilities in most languages nowadays, unless one is stuck on Go, C and similar.

replies(7): >>41878547 #>>41878579 #>>41878702 #>>41878783 #>>41878792 #>>41878816 #>>41879057 #
blackoil ◴[] No.41878783[source]
One difference with LINQ is its ubiquity. It works with database, in memory data structures, on disk files. You can use your skills/code across all the system.
replies(1): >>41878827 #
John23832 ◴[] No.41878827[source]
It's just built on top of anything that is Iterable. If a language has first class iterator support, they could do something similar.
replies(2): >>41878964 #>>41879023 #
mythz ◴[] No.41879023[source]
Takes a lot more than that, LINQ providers work by accepting a LINQ Expression Syntax tree instead of an opaque function, which allows providers to inspect and traverse the Expression's AST and translate it into the data source it's implementing.

This Expression AST is constructed by the compiler, not something that can be tacked on by a library later.

replies(2): >>41879354 #>>41879511 #
1. megadal ◴[] No.41879354[source]
Yes, but I think the point is practically every high level language can already do this pretty trivially.

If it's scripted you can typically just get a string representation of the function.

If it's Java, JAR inspection/dynamics have been a thing for a long time. And in other languages, they usually directly support metaprogramming (like Rust) and plugging code into the compilation logic.

replies(3): >>41879513 #>>41879690 #>>41880343 #
2. mythz ◴[] No.41879513[source]
If it were trivial you'd see LINQ-like providers implemented in "practically every high level language".

Source code of the function means you have to implement the parser/lexer to convert it into a usable AST which is bad for both runtime performance and library size.

Very much doubt this is available in Java, which Java ORM lets you use native Java language expression syntax to query a database?

replies(2): >>41879899 #>>41887222 #
3. eknkc ◴[] No.41879690[source]
Wait what? Am I gonna include a source code parser and AST analyser to my JavaScript library for example, to examine the provided expression source and do this? This reads like the infamous Dropbox comment from when it first got released.
replies(1): >>41887194 #
4. pjmlp ◴[] No.41879899[source]
jOOQ would be one such example, https://www.jooq.org/

Not that I use this, I am a myBatis person in what concerns database access in Java, and Dapper in .NET for that matter, not a big ORM fan.

And case in point most people use LINQ for in-memory datastructures, not the database part.

replies(1): >>41880000 #
5. mythz ◴[] No.41880000{3}[source]
This is a custom expression language to work within the expressive limitations of the language:

    create.select(BOOK.TITLE)
      .from(BOOK)
      .where(BOOK.PUBLISHED_IN.eq(2011))
      .orderBy(BOOK.TITLE)
If Java supported LINQ you'd be able to use a more intuitive and natural Java expression syntax instead:

    create.from<Book>()
     .where(x -> x.publishedIn == 2011)
     .orderBy(x -> x.title)
     .select(x -> x.title);
replies(1): >>41880030 #
6. pjmlp ◴[] No.41880030{4}[source]
Java streams are what you're looking for.

If you insist in telling LINQ === EF, well that isn't what most folks in .NET use System.Linq for.

And back to the ORM thing, jOOQ is one way, there are others, and even if it isn't 1:1 to "from x select whatever" the approach exists.

replies(2): >>41880082 #>>41880971 #
7. mythz ◴[] No.41880082{5}[source]
> If you insist in telling LINQ === EF

I don't use EF, nor have I ever mentioned it.

You're replying to a thread about what it takes to implement a LINQ provider, which was dismissed as every high level language implements it with iterables, then proceed to give non-equivalent examples.

8. jayd16 ◴[] No.41880343[source]
Not that I agree it's trivial but even if it was, so what?

This just feels like sour grapes.

replies(1): >>41887202 #
9. recursive ◴[] No.41880971{5}[source]
IQueryable<> manipulation has other tools available to it than brute-force iteration, like streams do. Streams may be the closest thing java has, but it's still a fundamentally different thing.
10. megadal ◴[] No.41887194[source]
You could also bundle your JS. Or pretend like any number of other solutions like caching parsed ASTs exist instead of being as obtuse as possible, or something idk
11. ◴[] No.41887202[source]
12. megadal ◴[] No.41887222[source]
I mean they kind of are. You can find a library in almost every language that transpiles source code ASTs.

They're just not core features.

In Haxe, it's extremely common :) but Haxe is just one other high level language.