Re:Diesel: A Safe, Extensible ORM and Query Builder for Rust
by u320 on Friday February 05, 2016 @08:23PM
(#11046028)
Yes I should have been more clear that I was talking about a static typing context. In a dynamic language the problem is much easier, as you are basically only limited by your languages metaprogramming facilities.
Re:Diesel: A Safe, Extensible ORM and Query Builder for Rust
by RussianCow on Friday February 05, 2016 @10:53PM
(#11046478)
But isn't the same true for a statically typed language with sufficiently powerful macros? I don't know if Rust falls into that category, having never used it, but I don't think it makes a difference whether the metaprogramming happens during compile time or runtime.
Re:Diesel: A Safe, Extensible ORM and Query Builder for Rust
by ossreality on Friday February 05, 2016 @11:33PM
(#11046562)
Yeah, if they're talking about what I think they're talking about, yes, something like LINQ could be implemented with macros (compiler plugin variant, I think) in Rust.
Re:Diesel: A Safe, Extensible ORM and Query Builder for Rust
by girvo on Saturday February 06, 2016 @05:14PM
(#11050196)
> basically only limited by your languages metaprogramming facilities
I'd like to point out that strong static-typing does not preclude powerful metaprogramming! Nim's macro system is extremely powerful because of it's great interplay between it and the type system.
For example, ActiveRecord doesn't have support for window functions, but its underlying AST (a library called ARel) allows you to extend it, which at one point I did, allowing me to write something like this:
which generates something like: (It's been a while since I looked at this particular code, which is no longer in production use, so it might not be correct.)In other words, I could continue to express whatever I wanted of SQL, at the language level — no type mismatches.
The SQL builder code isn't pretty, to be sure, but it's something you typically encapsulate into a lower-level module rather than writing in application code. And as it's highly analogous to the SQL code it generates, it's not like it's that much more complicated. (ARel isn't a shining example of how to do it right, either. I expect Diesel implements the AST aspect more cleanly.)
Edit: I see what you're saying about typed record types. I was thinking more about the grammar, not the shape of the data.