On 3/19/12 10:17 AM, Brian Palmer wrote:
On Monday, 19 March 2012 at 01:29:50 UTC, H. S. Teoh wrote:

In C++, for example, you can define operator<() and operator>() in
completely arbitrary ways, which means they can be totally unrelated to
each other, and return results that have nothing to do with each other.
This causes inconsistency in that a<b does not necessarily imply b>a,
and vice versa. Which makes for inconsistent code.

While I totally get that concern, I've never really seen it become a
real issue in any of the large C++ systems I've worked on. Maybe I've
just been lucky? Ruby also allows these arbitrary operator
redefinitions, and it's never been an issue in the large Ruby systems
I've worked on, either. Python also allows them, though I don't have
much Python experience.

I think the concern is not bugs in the implementation, but instead a lot of boilerplate text (e.g. in the C++ standard) and code (all of those mind-numbing one-liners that swap parameter order etc).

In fact, a lot of the most useful DSLs in Ruby rely heavily on being
able to do these overrides. I think D today is missing out on a lot of
those possibilities.

For D, hooking built-in operators is a poor way to implement DSLs. Best is to use strings, CTFE, and mixin.


Andrei

Reply via email to