[Issue 14593] operator overloading can't be used with expression templates

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Sep 10 04:06:31 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14593

Martin Nowak <code at dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WONTFIX                     |---

--- Comment #3 from Martin Nowak <code at dawg.eu> ---
(In reply to Walter Bright from comment #1)
> Using expression templates to implement DSL's makes code really hard to
> understand and debug.

I'm not advocating complex DSLs but there are a number of areas where
expression templates are the natural choice (matrix, vector, simd ops) b/c the
compiler already typechecks and does the usual operator precedence.
You even recommended that yourself here
https://github.com/D-Programming-Language/druntime/pull/471#issuecomment-16092197.

> There are better ways.

If you want to see one "better" way, look at MongoDB which named operators
instead of normal JS expressions.

db.inventory.find(
   {
     type: 'food',
     $or: [ { qty: { $gt: 100 } }, { price: { $lt: 9.95 } } ]
   }
)

> You may pass where condition as string, and use libdparse, or something like it to build AST and compile it to your SQL expression.
db.get!Person.where!(`p.age > 21 && p.name == "Peter"`)
This looks not worse, and at the same time, more honest.

I'd have to use a complex CTFE parser implementation to get the AST. And then
I'd still have to perform semantic analysis (bind names) and run typechecks,
this is fairly unfeasible.

The requested opBinary extension is a very small language addition and allows
for more efficient operators in general (opBinary!"<" vs. opCmp). Please
reconsider the decision.

--


More information about the Digitalmars-d-bugs mailing list