Short list with things to finish for D2

aarti_pl aarti at interia.pl
Sat Nov 21 10:21:10 PST 2009


Walter Bright pisze:
> Don wrote:
>> There's not many sensible operators anyway. opPow is the only missing 
>> one that's present in many other general-purpose languages. The only 
>> other ones I think are remotely interesting are dot and cross product.
> 
> Yup.
> 
>> Anything beyond that, you generally want a full DSL, probably with 
>> different precendence and associativity rules. Eg, for regexp, you'd 
>> want postfix * and + operators. There are examples of clever things 
>> done in C++  with operator overloading, but I think that's just 
>> because it's the only way to do DSLs in C++.
> 
> I was enthralled with the way C++ did it for regex for a while, but when 
> I think more about it, it's just too clever. I think it's more operator 
> overloading abuse now.
> 
>> I don't think the applications are there.
> 
> I agree.

Well, I can understand your fear about operator abuse. And I agree that 
code might be awful when operator overloading will be abused.

But I have in mind one very convincing example. I defined in D/Java SQL 
syntax. They are also other frameworks which do the same.

What can I say about my experiences with using such framework: it is 
very, very powerful concept. It cuts time necessary to develop 
application, makes sql statements type safe and allows to pass around 
parts of sql statements inside application. It also makes easy 
refactoring of sql statement (especially in Java). Its huge win 
comparing it to defining DSL as strings.

It's hard to explain just in few sentences all details. I have already 
done it long time ago, and in my first post I provided links.

Problem with current approach is that I have to define SQL in D/Java in 
following way:

auto statement = Select(visitcars.name).Where(And(More(visitcards.id, 
100), Like(visitcards.surname, "A*")));

Please look at code in Where(). It's so awfuuuuulllllll!

It would be so much better to write:
auto statement = Select(visitcars.name).Where((visitcards.id `>` 100) 
`AND` (visitcards.surname `Like` "A*"));

I used here syntax which you have proposed with delimiter ``. I think it 
is good enough solution for such purpose.

But please, don't underestimate problem! Many DSL languages would never 
appear if languages would be good enough.

As I said solution with delimiter is good enough for me. It has another 
advantage that it clearly shows in code that you have overloaded 
operator here, so no surprises here. Additionally when you implement 
template function:
opInfix('AND')(val0, val1);
you pass string into template. So I see it quite intuitive that you use 
string as operator: ``. Maybe there will be not necessary to change 
current behavior that `` defines string.

I think we have good possibility to  open this door now. It can be even 
implemented later, but I would wish just not to close this door now :-)

BR
Marcin Kuszczak
(aarti_pl)



More information about the Digitalmars-d mailing list