[524] 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 (Greg Wilkins)
Wed Jun 28 04:33:56 1995

From: Greg Wilkins <gregw@ind.tansu.com.au>
Date: Wed, 28 Jun 1995 17:57:20 +1000
To: java-interest@java.sun.com


 >From: "Henri BROUCHOUD - FT.CNET/LAA/EIA/AIA" <brouchou@lannion.cnet.fr>
 >
 >> Personally  I'm not too keen on operator overloading; while it's useful
 >> for extending the numeric types it makes people want to build things
 >> like C++'s iostreams.  Is the benefit really worth the cost?
 >
 >I thought Java was designed as C++ like, in order to make it "quite simple"
 >and short "to learn". I sincerely think operator overloading is one major 
 >feature of C++, I prefer to read 
 > [snip]
 >It seems to me that the expressivity and readibility of a language is an 
 >important point to make it easy, maintenable, extensible, and then popular
 >(I really don't like Tcl...).  Everybody's like sugar !

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, 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.  Most programmers are just not up to this, so when
users use their classes as if they were doing normal arithmatic, strange
results and subtle bugs often occur.   And automatic conversion can be
an absolute nightmare.

This is the can of worms the Java people decided to best leave shut.
While you may plead with them that sugar is nice, unless you can
find a way to avoid the many subtle bugs that can result, I fully
agree with their call.

-------------------------------------------------------------------------------
Greg Wilkins:Consultant for Object Oriented Pty. Ltd. (OOPL)|You're not Dorothy
       Site @Telecom, Intelligent Network Development       |I'm not Toto!
       Snail:P.O. Box 1826,North Sydney,NSW.2089, Australia |And this
       Email:gregw@ind.tansu.com.au (gregw@oose.com.au)     |definitely is 
       Fax  :(+61 2) 3953225 or OOPL Office:(+61 2) 9565089 |not Kansas!
       Phone:(+61 2) 3953461 or OOPL Office:(+61 2) 9571092 |  -Fleischman
-------------------------------------------------------------------------------
-
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