No household is perfect
Brad Anderson
eco at gnuk.net
Tue Dec 3 12:19:34 PST 2013
On Tuesday, 3 December 2013 at 20:06:49 UTC, Walter Bright wrote:
> On 12/3/2013 4:41 AM, Russel Winder wrote:
>> Yes.
>>
>> a + b
>>
>> could be set union, logic and, string concatenation. The + is
>> just a
>> message to the LHS object, it determines what to do. This is
>> the whole
>> basis for DSLs.
>
> Using operator overloading to create a DSL is just wrong. Part
> of the design of operator overloading in D is to deliberately
> frustrate such attempts.
>
> + should mean addition, not union, concatenation, etc.
> Overloading is there to support addition on user defined types,
> not to invent new meanings for it.
>
> Embedded DSLs should be visually distinct, and D provides the
> ability for that with string mixins and CTFE.
>
>
> Part of my opinion for this comes from C++ regexes done using
> expression templates. It's cute and clever, but it's madness.
> For one, any sort of errors coming out of it if a mistake is
> made are awesomely incomprehensible. For another, there's no
> clue in the source code when one has slipped into DSL-land, and
> suddenly * doesn't mean pointer dereference, it means "0 or
> more".
>
> Utter madness.
Indeed. I had a regex bottleneck in a C++ program so I figured
I'd just convert it to Boost Xpressive as an easy solution. It
took me half a day to convert the regular expression into the
convoluted single line of code with dozens of operators it
became. It did run faster (phew!) so it was worth it but the code
is unrecognizable as a regular expression and I have to keep a
comment with the original regular expression in the code because
nobody (myself included) should have to spend an ungodly amount
of time trying to decipher the cryptic source code it became.
If my program were written in D I would have just replaced
"regex(" with "ctRegex!(" and moved on with my day.
More information about the Digitalmars-d
mailing list