3 ms·
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
by megadal 2y ago
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.
- mythz 2y agoIf 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?
- pjmlp 2y agojOOQ would be one such example, https://www.jooq.org/ 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.
- mythz 2y agoThis 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);
- pjmlp 2y agoJava 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.
- mythz 2y ago> 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.
- recursive 2y agoIQueryable<> 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.
- megadal 2y agoI 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.
- eknkc 2y agoWait 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.
- megadal 2y agoYou 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
- jayd16 2y agoNot that I agree it's trivial but even if it was, so what? This just feels like sour grapes.
- deleted 2y ago[deleted]