Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Advocacy > Operator Overlo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 7 Topic 2407 of 2478
Post > Topic >>

Operator Overloading (Was: In Praise of Strong Typing)

by Daniel Pitts <newsgroup.spamfilter@[EMAIL PROTECTED] > Jun 22, 2008 at 03:52 PM

Roedy Green wrote:
> On Sun, 22 Jun 2008 11:21:34 -0700, Daniel Pitts
> <newsgroup.spamfilter@[EMAIL PROTECTED]
> wrote, quoted or indirectly
> quoted someone who said :
> 
>> There have been times where I have heavily missed operator overloading 
>> in Java :-)
> 
> My Forth background makes me too yearn for the elegance of operator
> notation for my own functions.  
> 
> However, you don't need overloading to get the benefits of operator
> notation.   If you were allowed to define a new operator that looked
> like + but looked slightly different, the code would have the elegant
> terseness of  operator overloading without the confusion as to when
> you are using a primitive and when the new definition.
> 
> see http://www.unicode.org/charts/PDF/U2A00.pdf
and
> http://www.unicode.org/charts/PDF/U2200.pdf
> for some possibilities.
> 
> I have never seen an example of operator overloading that was not
> utterly confusing.  Code is automatically bad if you use the feature.
> It as not a matter of ALLOWING you to write bad code. It FORCES you to
> write bad code.
> 
This is not bad code (albeit C++ code)
Vector operator+(const Vector &left, const Vector &right) {
     Vector result;
     for (int i = 0; i < Vector::size; ++i) {
        result[i] = left[i] + right[i];
     }
     return result;
}
....
myNewVect = someVect + someOtherVect;


Terseness for its own sake is inexcusable. However, the "terseness" 
above actually makes it more readable.

The problem I think comes when you mix operator overloading with 
polymorphic types in a single-dispatch system.  Java, of course, is a 
single-dispatch system, so operator overloading *may* be difficult to 
implement in a way that makes sense.

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 




 7 Posts in Topic:
In Praise of Strong Typing
Roedy Green <see_websi  2008-06-22 16:53:28 
Re: In Praise of Strong Typing
Daniel Pitts <newsgrou  2008-06-22 11:21:34 
Re: In Praise of Strong Typing
Roedy Green <see_websi  2008-06-22 20:07:33 
Operator Overloading (Was: In Praise of Strong Typing)
Daniel Pitts <newsgrou  2008-06-22 15:52:00 
Re: Operator Overloading (Was: In Praise of Strong Typing)
Bartlomiej Golenko <ba  2008-06-23 02:00:06 
Re: Operator Overloading (Was: In Praise of Strong Typing)
ram@[EMAIL PROTECTED] (S  2008-06-23 02:38:59 
Re: Operator Overloading (Was: In Praise of Strong Typing)
Daniel Pitts <newsgrou  2008-06-22 21:43:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Dec 4 1:18:03 CST 2008.