[1022] in java-interest

home help back first fref pref prev next nref lref last post

Re: Operator Overloading

daemon@ATHENA.MIT.EDU (Tom Wheeler)
Wed Aug 16 23:17:28 1995

Date: Wed, 16 Aug 95 08:34:35 EDT
From: tomw@intelligraphics.com (Tom Wheeler)
Reply-To: tomw@intelligraphics.com (Tom Wheeler)
To: java-interest@java.Eng.Sun.COM

>Yes, but isn't it interesting that the only examples operator-overloading
>proponents use are either the one above or numeric types such as matrices?
>Java already supports the above as a special hack for Strings.  You'll 
>find it much more difficult to come up with a compelling example using
>any of Java's AWT or Net classes.

Well of course operator-overloading usually makes the most sense with
numeric types!  If you overload mathematical operators to mean something
totally different people won't be able to read the code (at least, not
until they get used to the different meaning.)  And as for other operators,
you shouldn't create new meaning for them either that aren't intuitive.
It would be like calling a function "printf()" and having it calculate
the length of the hypotenuse of a right triangle given the other two
sides.

In fact, I consider the typical overloading example of Strings to
be horrible.  string1 + string2 has no mathematical meaning - it's
concatenation, and the only reason everybody understands it and accepts
it is because as prepubescent boys and girls we all learned BASIC.

IMO operator overloading has its place.  It can and does make code
easier to read and write.  Like any other language feature it can be 
abused and misused, but that isn't a reason to keep it out of a 
language.  If that was the criterion for including features in a 
language we'd all still be writing programs in Pascal.


Regards,
Tom Wheeler
tomw@intelligraphics.com

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post