

Rogue: A Type-Safe Scala DSL for querying MongoDB - abraham
http://engineering.foursquare.com/2011/01/21/rogue-a-type-safe-scala-dsl-for-querying-mongodb/

======
nathanwdavis
Looks nice. It kind of reminds me of LINQ (in spirit)

------
Devilboy
Why is is that every MongoDB article on HN gets to the font page with 25-odd
points but almost no comments? I see them several times a week.

~~~
alnayyir
They know they love it, but have almost nothing intelligent to say about it.
I'd consider that a virtue as opposed to the alternative.

------
tedjdziuba
Getting further along in the process of re-inventing SQL, I see.

~~~
jorgeortiz85
Any sufficiently complicated database contains an ad hoc, informally-
specified, bug-ridden, slow implementation of half of SQL.

...including every SQL database.

~~~
mahmud
Except for Datalog, Prolog, SPARQL, XQuery, etc. which are non-SQL database
query languages.

------
alnayyir
I'll bite since no one else has asked.

What makes type-safety the most important property of a DSL for querying a
database to note when introducing it?

~~~
narrator
It means that your IDE can add all sorts of auto complete magic and cross-
referencing if it knows the types and semantics of the code it is displaying.
It can also prevent runtime errors to some extent via static analysis of the
query.

~~~
alnayyir
I like MongoDB, but am familiar enough with type-obsessed languages like
Haskell and Scala to summarize your response as

"not much"

I'd argue there are potentially better priorities available for a DSL->DB
mapper. But hey, they're the ones putting themselves out there and putting in
the hard work, not me.

So, more power to them and I'm glad they're contributing back to the
community.

~~~
jorgeortiz85
A common software engineering practice whenever one runs into a bug in
production is to say "How can I make sure this class of bugs results in a test
failure in the future?"

With a good type system, you can take that thought one step further and say,
"How can I make sure this class of bugs results in a compilation failure in
the future?"

Rogue lets us do that. The DSL is both expressive (it covers almost all of
Mongo's query features) and easy to use (Rogue queries are concise and very
similar to Mongo queries), yet they eliminate (at compile time!) a whole class
of bugs that have bitten us in the past. When your Rogue query compiles, you
can be fairly certain that it will generate a well-formed Mongo query. Getting
a similar guarantee from a test suite would involve a lot more work.

~~~
rbarooah
Jorge - rogue looks great, and had it existed when I started my current
project I might well have picked scala rather than clojure and congomongo
(which is great too).

However - when you say it would have involved more work to guarantee well
formed queries from a test suite, I find myself wondering how that can be true
if you test every function that hits the database. Wouldn't malformed queries
would cause such tests to fail?

