Operator overloading
aarti_pl
aarti at interia.pl
Tue Dec 23 14:29:01 PST 2008
dennis luehring pisze:
> aarti_pl schrieb:
>> Ary Borenszweig pisze:
>>> dennis luehring escribió:
>>>>> ...
>>>>> This translation is quite awful and unreadable. It would be so much
>>>>> better to get:
>>>>>
>>>>> Query query = Select(a).Where(id == 5);
>>>>
>>>> what speaks against an sql parsing mixin?
>>>>
>>>> would be more expressive, compiletime based and typesafe
>>>> and even far more be able than what you can do with operator
>>>> overloading
>>>
>>> Autocompletion and syntax coloring.
>
>> Yes. And additionally:
>> * you can not build safely your queries on runtime
>
> that even not possible with operators - or?
It is possible and it works :-)
But with operator overloading it is so much more readable, than without it.
Creating queries at runtime is quite common:
age = 20;
string query = "Select name, surname FROM persons WHERE age = " +
to!(string)(age);
>> * when moving Query around in program you will not be able to make it
>> typesafe, because it is just string
>
> not if you parse the string at compiletime an use the
> type information from outer scope for validation
Compile time checking of SQLs will not be enough for any bigger program.
How would you insert your data into database? INSERT needs values which
are taken e.g. from GUI and completely unknown at compile-time.
>> * in my db access system it won't be possible to automatically create
>> database, typesafely get results from resulting table and few other
>> nice features...
>
> just a quick look into blades (library with vector math language
> extensions - based on compiletime strings)
>
> http://www.dsource.org/projects/mathextra/browser/trunk/blade/BladeDemo.d
>
> don referes to outer vars in his "strings" and you can typecheck them
It doesn't solve all problems. Just a one.
BTW. In recent release Boost team added a whole brand new library for
domain specific languages embedded languages called Proto. I think that
it means that there is quite a big need for such features. E.g. for
mocking frameworks which will also profit from extended DSL sublanguages
support in programming languages.
BR
Marcin Kuszczak
(aarti_pl)
More information about the Digitalmars-d
mailing list