[525] in java-interest

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

Re: Operator overloading (was: BigInteger class out there?)

daemon@ATHENA.MIT.EDU (Michael Lorton)
Wed Jun 28 13:01:03 1995

Date: Wed, 28 Jun 1995 09:32:03 -0700
From: Michael Lorton <mlorton@eshop.com>
To: java-interest@java.sun.com
In-Reply-To: Greg Wilkins's message of Wed, 28 Jun 1995 17:57:20 +1000 <199506280757.RAA09646@ostrich.cssc-syd.tansu.com.au>


   [Greg Wilkins <gregw@ind.tansu.com.au> writes]

   While there are many examples where operator overloading makes code 
   more readable, there are also many many examples were operator
   overloading introduces subtle bugs.

   Once you have operator overloading, your really need automatic 
   conversions to make the sugar look really nice,

I would strenuously disagree here.  Automatic conversions are a tool of
the devil.  :-)>

   then you really need
   a degree in pure maths to work out the group theory for any non-trival
   classes that you want to use these features for.

   If it looks like * it needs to act like *, so the group of all your 
   classes instances needs to be reflexive, transitive, have a unity 
   instance etc. etc.

I disagree here also.  If I were writing a Matrix class, I would very
much like to overload the *.  I would certainly NOT want reflexivity,
since bA != Ab.  Moreover, the same argument could apply against
methods with operator-like names (multiply() or add()).

Any tool can be misused.  The question is does the potential cost of
abuse exceed (or even approach) the benefit of proper use.  In the
case of automatic conversion, I agree with the growing consensus that
says yes.  I am not convinced about operator overloading; group theory
is not going to convince me.

M.

-
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