[543] in java-interest

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

Re: Operator overloading (was BigInteger)

daemon@ATHENA.MIT.EDU (Tom Wheeler)
Thu Jun 29 13:16:48 1995

Date: Thu, 29 Jun 95 11:25:34 EDT
From: tomw@intelligraphics.com (Tom Wheeler)
Reply-To: tomw@intelligraphics.com (Tom Wheeler)
To: java-interest@java.Eng.Sun.COM

> Besides "looking better", I've found that some operator overloading also
>helps with code maintainability. Since I'm dealing with tight memory

I've found this to be true.  It can also help make code more readable.
To use the standard example of strings:

  s1.assign (s2);
  s1.append (s3);

Or

  s1 = s2 + s3;

Of course the problem(s) come in when we assume certain behaviors or
characteristics because we are used to the mathematical properties of
operators.  But consider: everyone knows what "s1 + s2" means because
we all learned it in our prepubescent days of BASIC.  Other meanings
for mathematical operators can also be learned; witness the use of
<< and >> for C++ iostreams.  In short, it's a matter of symbols.
Operators are symbols just as words are.  They convey a particular
meaning, or idea.  Why should we allow overloading of English symbols
and not mathematical symbols?

>I agree that operator-overloading is not worth the cost. This is especially
>true when, at least in C++, you often can't get operator-overloading to
>generate the code you want to do anyways (like with the + operator).

I assume you are referring to the commutative property, e.g. a + b == b + a.
This is a _mathematical_ property, and people simply assume that it holds
in programming as well.  This assumption must be dealt with by making it
very clear that just because a mathematical operator is used in a language
the operation may not follow mathematical convention - and in fact the
behavior of the operator may not follow mathematical convention, as of
course is the case with Strings.

> The only benefit I've found to template functionality has been for speed
>and memory critical aspects of a program. I've come to the conclusion that

I think they're a somewhat useful but rather ugly hack.  (But then, that's
what I think of much of C++.)


Regards,
Tom Wheeler

-
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