Eigenpoll : D wish list : {Cleaner Operator Overloading} 

Let's say I want to overload the /= operator.. hm.. Should it be divAssign or opDivideAssign.. or opDivAssign.. or something else...?
As you see, op overloading requires learning all those cumbersome keywords by heart if you don't want to waste your time flicking through the D specs to find the one you need.

There's a better way:

class Foo {
real bar;
double[] ArrayofDoubles;

void op(Foo res /= Foo div) {
res.bar /= div.bar;
}

Foo op(Foo a + Foo b) {
return = a.bar + b.bar;
}

double op(Foo a[int i]) {
return a.ArrayofDoubles[i];
}

// and so on...
}

The idea is to introduce an "op" (possibly "operator") keyword and say what operator you want in the brackets. Forcing the user names instead of just using the symbols, which he/she is already familiar with is a waste of time.

Not to mention that it allows to do some other useful things like...

class Guy {
uint health;
uint firepower;
uint ammo;

void op(Guy a shoots Guy b) {
b.health -= a.firepower;
a.ammo--;
}
}

Guy goodGuy = new Guy();
Guy badGuy = new Guy();

badGuy shoots goodGuy;


In other words, it allows more natural syntax where you need it.

I really think it's a good idea. Support it and make D a better language!




Report this item for cleanup