Roedy Green wrote:
> On Sun, 22 Jun 2008 11:21:34 -0700, Daniel Pitts
> <newsgroup.spamfilter@[EMAIL PROTECTED]
> wrote, quoted or indirectly
> quoted someone who said :
>
>> There have been times where I have heavily missed operator overloading
>> in Java :-)
>
> My Forth background makes me too yearn for the elegance of operator
> notation for my own functions.
>
> However, you don't need overloading to get the benefits of operator
> notation. If you were allowed to define a new operator that looked
> like + but looked slightly different, the code would have the elegant
> terseness of operator overloading without the confusion as to when
> you are using a primitive and when the new definition.
>
> see http://www.unicode.org/charts/PDF/U2A00.pdf
and
> http://www.unicode.org/charts/PDF/U2200.pdf
> for some possibilities.
>
> I have never seen an example of operator overloading that was not
> utterly confusing. Code is automatically bad if you use the feature.
> It as not a matter of ALLOWING you to write bad code. It FORCES you to
> write bad code.
>
This is not bad code (albeit C++ code)
Vector operator+(const Vector &left, const Vector &right) {
Vector result;
for (int i = 0; i < Vector::size; ++i) {
result[i] = left[i] + right[i];
}
return result;
}
....
myNewVect = someVect + someOtherVect;
Terseness for its own sake is inexcusable. However, the "terseness"
above actually makes it more readable.
The problem I think comes when you mix operator overloading with
polymorphic types in a single-dispatch system. Java, of course, is a
single-dispatch system, so operator overloading *may* be difficult to
implement in a way that makes sense.
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>


|