Overloading relational operators separately; thoughts?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 29 00:58:26 PDT 2016


On 9/28/2016 11:48 PM, Jacob Carlborg wrote:
> If that is not allowed, why is this allowed:

I.e. you can overload '+' to do bad things. Yes, you can, and as I replied 
upthread that can be done because there's no way to prevent that while having 
operator overloading at all.

But that is not justification for allowing such disasters for the comparison 
operators. I.e. one weakness is not justification for opening the door to all 
weakness.

Interestingly, by shutting the door on misuse of the comparison operators, it 
seems D has been successful in discouraging nutburger designs like overloading 
'+' to mean 'OR'.


> The language you just provide a set of tools, then it's up the to the programmer
> to do what he/she wants to do.

That can be used to justify any feature at all.


>> The use of them to create DSLs (a technique called "expression
>> templates" in C++) is discouraged in D, for several reasons. The
>> recommended way to create DSLs in D is to parse strings using CTFE.
>
> That's one of the ugliest things about D. Because suddenly you will not have any
> help of any tools, like editors, IDEs, linters, syntax analysis and so on. One
> also needs to implement a complete parser, how many complete parsers do we have
> for D?

I know you really want AST macros for D. We've discussed that at length before.

BTW, there's a CTFE parser generator for D around somewhere.


More information about the Digitalmars-d mailing list