Operator overloading

dennis luehring dl.soluz at gmx.net
Tue Dec 23 23:29:47 PST 2008


> 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);

that is not object + operator based - your flexibilty here comes from 
your string and the "runtime" interpretation of the sql semantic in your 
database ...

if you need an additional "LIKE" based on an codition you need to 
rebuild your object/operator concatination in complete:

if( gui.checkbox == true )
{
   SELECT a from b
}
else
{
   SELECT a from b WHERE c LIKE '% ~ C ~ %'
}

> 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.

why is a value that comes from an gui not compile-time?
not the value is what you need - its the type (when we talk about type 
safetyness)

how does vector-array get into Don's Blade strings? and why do i get
compile-time errors when using the wrong type inside of the string?

and you can't even speak of type-safetyness when using only strings in 
your database communication - how can be your results typesafe
(i don't like string[string] results-set) because the safetiness is 
programatical

> 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.

you should read into the details of using mixins - they are much much 
more flexible than you think (not just boring strings) - and with the 
base feature-set of D something like mock wouldn't even exist
and what the boost guys to is to get around c++ base feature-set to 
express new thing with c++

@Ary does syntax coloring and smart auto-completen help while writing
spirit based parsers? the complete meaning of ( * - \ ... is different 
to "normal" code

btw: don syntaxtree is also an great example of using mixins
http://www.dsource.org/projects/mathextra/browser/trunk/blade/SyntaxTree.d



More information about the Digitalmars-d mailing list