There is no different from normal Java method.

Like if we have method add, but when call it, it will read data from database and display it (not add anything), is Java method a problem? ]]>

But if you have to write software in the domain of arithmetics, for example 3D applications, cryptographic software, financial software or any kind of scientific software you are really missing operator overloading in Java a lot.

Just think about something like rendering algorithms (like raytracing, pathtracing, ambient occlusion and such stuff) where you have to compute the orthonormal base.

In a language with operator overloading you can write something like:

Vector3 d = (u * Math.Cos(r1) * r2s + v * Math.Sin(r1) * r2s + w * Math.Sqrt(1.0 – r2)).normalize();

in Java you would have to write something like

Vector3 d = ((u.vecsmul(Math.cos(r1) * r2s)).vecadd(v.vecmul(Math.sin(r1) * r2s)).vecadd(w.smul(Math.sqrt(1.0 – r2)))).normalize();

or when using static methods:

Vector3 d = (Vector3.vecadd(Vector3.vecadd(Vector3.vecsmul(u, Math.cos(r1) * r2s), Vector3.vecsmul(v, Math.sin(r1) * r2s)), Vector3.vecsmul(w, Math.sqrt(1.0 – f2)))).normalize();

or doing it the simple way:

Vector3 d = new Vector3();

d.x = (u.x * Math.Cos(r1) * r2s + v.x * Math.Sin(r1) * r2s + w.x * Math.Sqrt(1.0 – r2));

d.y = (u.y * Math.Cos(r1) * r2s + v.y * Math.Sin(r1) * r2s + w.y * Math.Sqrt(1.0 – r2));

d.z = (u.z * Math.Cos(r1) * r2s + v.z * Math.Sin(r1) * r2s + w.z * Math.Sqrt(1.0 – r2));

d.normalize();

This is just a tiny example. There are much more complicated formulas and things can really get nearly unreadable when it gets more complicated.

It can also be a source of errors when translating formulas from paper in your programming language since it is not easy to see on first sight if the translated formula is the same as on paper.

Another bad things when not having operator overloading in the language is that you have to memorize the function names for doing arithmetics.

So for arithmetic stuff like arbitrary-sized large integers (Bignum in java), Fractional (int/int) number representations, Base-10 floats for rounding issues (financial software), Arbitrary-precision floating-point numbers, complex numbers, quaternions, vectors, matrices and defining your own arithmetic for cryptography (like elliptic curves) i really miss operator overloading a lot in java. And for me it is really a reason not to use it for that kind of software. ]]>

“””

… elegant uses in Smalltalk:…

“Yes fractions, making irrational numbers possible”

3/7 + 5/6.

…

“””

But doesn’t 3/7 + 5/6 in fact mean the same as (((3/7)+5)/6) in Smalltalk (left-to-right evaluation)? I think it does, and I think this an insane design decision – screwing up one of the two most useful applications of binary operators (the other one being comparison operators).

I think Scala does much better; precedence when using methods as binary operators is worked out from their names, in a way consistent with standard arithmetic. ]]>

Off the top of my head how about these for starters:

“Yes fractions, making irrational numbers possible”

3/7 + 5/6.

“How about complex numbers anyone?”

(2 +3i)

“Ever wanted to send several messages to the same object?”

receiver doThis, andThis, andAlsoThis.

Thats before we get to advance uses like this BNF expressed in Newspeak:

id = letter, (letter | digit) star.

I just don’t understand how people adopt such strong views, based on such limited experience. Yes I do. We all love the comfort you get from saying “I Know It Already”, even when we possibly don’t.

Ah, well such is human nature ðŸ™‚ ]]>

BigDecimal, Matrices, Measurements, Money

I can’t understand why you speak about Collections. Of course arithmetic operator overloading in Collections is not good idea ðŸ˜‰

But having some analog of operator []= for user-defined classes can be useful.

(And as I understand from project coin, java 7 will have overloaded array index access for collections) ]]>