Overloading relational operators separately; thoughts?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 27 20:12:05 PDT 2016


On Wednesday, September 28, 2016 01:18:58 Minty Fresh via Digitalmars-d wrote:
> So, I'm just interested in other people's thoughts are on the
> subject, and whether there are any plans to allow overloading
> these operators separately.

Basically, having them be overloaded separately is error-prone, and it leads
to folks overloading them in ways that have nothing to do with what they
mean for the built-in types, which makes code harder to read and maintain.
D has a concatenation operator specifically because Walter thought that it
was horrible to use + for concatenation.

If you want to write DSLs, then use strings and mixins. D gives you a _lot_
of power in that area, and it avoids the problems associated with making
overloaded operators do things other than what those operators are normally
intended to do. With strings, you can make your DSL look however you want -
even doing stuff like using various Unicode symbols as operators if you want
to. Even with how C++ overloads operators, overloading operators gives you
fairly limited options with what you can do with a DSL, whereas you have
full freedom with strings - and without the problems that come with trying
to make your DSL look like normal D code.

- Jonathan M Davis



More information about the Digitalmars-d mailing list