<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Operator Overloading: Trickier Than it Looks</title>
	<atom:link href="http://cafe.elharo.com/blogroll/operator-overloading/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/operator-overloading/</link>
	<description>Longer than a blog; shorter than a book</description>
	<pubDate>Fri, 21 Nov 2008 16:12:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: yaser</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-253501</link>
		<dc:creator>yaser</dc:creator>
		<pubDate>Mon, 28 Jul 2008 23:48:03 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-253501</guid>
		<description>how can i overload an operator in a generic class in c#?</description>
		<content:encoded><![CDATA[<p>how can i overload an operator in a generic class in c#?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred Swartz</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-216962</link>
		<dc:creator>Fred Swartz</dc:creator>
		<pubDate>Mon, 14 Apr 2008 20:03:45 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-216962</guid>
		<description>&lt;b&gt;Predefined overloaded operators&lt;/b&gt; for the Collections class operations, BigInteger, etc would be very nice.

&lt;b&gt;User defined operators&lt;/b&gt; don't seem objectionable in actual practice.  I've rarely seen them abused in real C++ programs.  There are plenty of features that can be misused, but most are not because of education, social pressure, or most often just good sense.  The programmer who overloads + for Apples would be likely to write a plus() method too.

&lt;b&gt;Units&lt;/b&gt; and range restrictions are something I really, really miss in Java.   These are so awkward to implement that people use unitless ints for their apples, which does allow the dreaded apples**2 .   Allowing operator overloaded and/or implementing units would surely reduce the number of squared apples.</description>
		<content:encoded><![CDATA[<p><b>Predefined overloaded operators</b> for the Collections class operations, BigInteger, etc would be very nice.</p>
<p><b>User defined operators</b> don&#8217;t seem objectionable in actual practice.  I&#8217;ve rarely seen them abused in real C++ programs.  There are plenty of features that can be misused, but most are not because of education, social pressure, or most often just good sense.  The programmer who overloads + for Apples would be likely to write a plus() method too.</p>
<p><b>Units</b> and range restrictions are something I really, really miss in Java.   These are so awkward to implement that people use unitless ints for their apples, which does allow the dreaded apples**2 .   Allowing operator overloaded and/or implementing units would surely reduce the number of squared apples.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mattchu</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-213826</link>
		<dc:creator>Mattchu</dc:creator>
		<pubDate>Sat, 05 Apr 2008 15:20:02 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-213826</guid>
		<description>If operator overloading is really that bad, then I must of been condemned to C++ Hell. My assignment in college is to develop a program that overloads all math operators, the cin, the cout, and the equals sign.

What if it's the case where we have no choice but to overload a bunch of math operators?</description>
		<content:encoded><![CDATA[<p>If operator overloading is really that bad, then I must of been condemned to C++ Hell. My assignment in college is to develop a program that overloads all math operators, the cin, the cout, and the equals sign.</p>
<p>What if it&#8217;s the case where we have no choice but to overload a bunch of math operators?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafael Vasquez</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-208740</link>
		<dc:creator>Rafael Vasquez</dc:creator>
		<pubDate>Sat, 22 Mar 2008 11:17:22 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-208740</guid>
		<description>The true usefulness of operator overloading comes with generic programming, which is sadly extremely limited in Java. Just try to do stuff like position += delta in a generic way without operator overloads..

Combine this with something like C++09 concepts, which do a compile-time check on the operands, and you get compile-time safety for these overloads (well, its possible even with C++98, but its non-trivial).

This outlines an important fact: operator overloads are *very* useful, BUT need very strict checks, since they can be abused very easily. C++ is getting there with concepts, Haskell got it right. Java decided not to deal with that problem simply by throwing out operator overloads altogether, thus diminishing its expressiveness. (Its real sin are the heavily castrated Generics, though - if Java Generics were a match to C++ templates, it would be a far more powerful language, especially because they had the chance to design a different syntax, much better suited for the tasks that C++ templates are used in today).

A great problem seems to be that many people still see operator overloads and the like from a 90s point of view. Just have a look at stuff like Boost, Generic Haskell, the upcoming C++09 standard, and then talk about operator overloads again.</description>
		<content:encoded><![CDATA[<p>The true usefulness of operator overloading comes with generic programming, which is sadly extremely limited in Java. Just try to do stuff like position += delta in a generic way without operator overloads..</p>
<p>Combine this with something like C++09 concepts, which do a compile-time check on the operands, and you get compile-time safety for these overloads (well, its possible even with C++98, but its non-trivial).</p>
<p>This outlines an important fact: operator overloads are *very* useful, BUT need very strict checks, since they can be abused very easily. C++ is getting there with concepts, Haskell got it right. Java decided not to deal with that problem simply by throwing out operator overloads altogether, thus diminishing its expressiveness. (Its real sin are the heavily castrated Generics, though - if Java Generics were a match to C++ templates, it would be a far more powerful language, especially because they had the chance to design a different syntax, much better suited for the tasks that C++ templates are used in today).</p>
<p>A great problem seems to be that many people still see operator overloads and the like from a 90s point of view. Just have a look at stuff like Boost, Generic Haskell, the upcoming C++09 standard, and then talk about operator overloads again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Jordan</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-199925</link>
		<dc:creator>Eric Jordan</dc:creator>
		<pubDate>Tue, 04 Mar 2008 01:42:39 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-199925</guid>
		<description>By way of disclosure, I am a math/physics major who did all that abstract nonsense in school, and I currently do mostly financial, physics, and graphics programming, so I'm pretty biased here.

In any case, here's the problem - I can get behind the claim that there are very few reasonable uses of operator overloading other than the canonical mathematical ones (vectors, matrices, big numbers, quaternions, etc.).  The apples/oranges example is not great.  That's fine.  But since Java doesn't include a decent assortment of mathematical objects that follow usual mathematical notations within the language, it is ridiculous that it also doesn't include the ability to add this functionality.  This is why people keep complaining - because they are tired of the parenthesis-soup that results when you try to write out simple vector equations.

If Java contained built in Vec2, Vec3, Matrix, and Quaternion types that used the usual operators (yes, I understand that adding two matrices of different size would cause an exception), I would be happy (happier if they behaved as value-types and could be reasonably quickly created for temp purposes, unmet-and-delayed promises of escape analysis notwithstanding), and I would gladly accept the fact that it allows no operator overloading.  Lacking that, Java is obnoxiously deficient for mathematical purposes (which, to be fair, Sun has told us many times they don't care very much about), and the only reasonable solution I can see is to allow overloading.

If you want to protect everyone from the bad programmers, then you have to at least give the good ones the tools they need to be productive and write readable code.  Otherwise Java will continue down the path it's on, until its sad death when all the halfway decent programmers have decided that they have no interest in programming a weak language that's designed for bad programmers.  I truly hope this doesn't happen, because I happen to love the language otherwise.</description>
		<content:encoded><![CDATA[<p>By way of disclosure, I am a math/physics major who did all that abstract nonsense in school, and I currently do mostly financial, physics, and graphics programming, so I&#8217;m pretty biased here.</p>
<p>In any case, here&#8217;s the problem - I can get behind the claim that there are very few reasonable uses of operator overloading other than the canonical mathematical ones (vectors, matrices, big numbers, quaternions, etc.).  The apples/oranges example is not great.  That&#8217;s fine.  But since Java doesn&#8217;t include a decent assortment of mathematical objects that follow usual mathematical notations within the language, it is ridiculous that it also doesn&#8217;t include the ability to add this functionality.  This is why people keep complaining - because they are tired of the parenthesis-soup that results when you try to write out simple vector equations.</p>
<p>If Java contained built in Vec2, Vec3, Matrix, and Quaternion types that used the usual operators (yes, I understand that adding two matrices of different size would cause an exception), I would be happy (happier if they behaved as value-types and could be reasonably quickly created for temp purposes, unmet-and-delayed promises of escape analysis notwithstanding), and I would gladly accept the fact that it allows no operator overloading.  Lacking that, Java is obnoxiously deficient for mathematical purposes (which, to be fair, Sun has told us many times they don&#8217;t care very much about), and the only reasonable solution I can see is to allow overloading.</p>
<p>If you want to protect everyone from the bad programmers, then you have to at least give the good ones the tools they need to be productive and write readable code.  Otherwise Java will continue down the path it&#8217;s on, until its sad death when all the halfway decent programmers have decided that they have no interest in programming a weak language that&#8217;s designed for bad programmers.  I truly hope this doesn&#8217;t happen, because I happen to love the language otherwise.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat Farrell</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-187106</link>
		<dc:creator>Pat Farrell</dc:creator>
		<pubDate>Fri, 08 Feb 2008 03:40:10 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-187106</guid>
		<description>The only good operator overloading that I've seen in "+" for string concatenation. ADA was the first language that I saw that had it, and I thought it was cool, because you could define Operator Overloading for Money and have it work the way people thing it does.

But as I've gotten older, I've grown to dislike it intensely.

Back when we engineers were taught to use slide rules, we were taught to work out the units in our head. Feet x pounds should give you torque, in either foot-pounds or pound-feet.

The idea of 'apple^2' is really dumb. Its not often part of folks brainwaves, but you never multiply money, you multiply one money quantity by a dimensionless number.

I totally agree. then again, I have a BS in Mathematics, and like fields, groups, isomophisms, etc.</description>
		<content:encoded><![CDATA[<p>The only good operator overloading that I&#8217;ve seen in &#8220;+&#8221; for string concatenation. ADA was the first language that I saw that had it, and I thought it was cool, because you could define Operator Overloading for Money and have it work the way people thing it does.</p>
<p>But as I&#8217;ve gotten older, I&#8217;ve grown to dislike it intensely.</p>
<p>Back when we engineers were taught to use slide rules, we were taught to work out the units in our head. Feet x pounds should give you torque, in either foot-pounds or pound-feet.</p>
<p>The idea of &#8216;apple^2&#8242; is really dumb. Its not often part of folks brainwaves, but you never multiply money, you multiply one money quantity by a dimensionless number.</p>
<p>I totally agree. then again, I have a BS in Mathematics, and like fields, groups, isomophisms, etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Drew Thaler</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-159873</link>
		<dc:creator>Drew Thaler</dc:creator>
		<pubDate>Fri, 23 Nov 2007 22:00:47 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-159873</guid>
		<description>As Werner said above, as long as you can define a consistent algebra then overloading is fine. Any class which implicitly represents a number is a natural candidate -- BigInteger, BigDecimal, Rational, Complex, etc. 

Other cases where I've used operator overloading (in C++) involved "normal" types that were wrapped in a class because they needed to be proxied somehow: atomic integers and pointers, byte-swapped integers, and objects in another address space which have to be accessed by DMA. (The last for the PS3 SPU.) All fine candidates for overloading.</description>
		<content:encoded><![CDATA[<p>As Werner said above, as long as you can define a consistent algebra then overloading is fine. Any class which implicitly represents a number is a natural candidate &#8212; BigInteger, BigDecimal, Rational, Complex, etc. </p>
<p>Other cases where I&#8217;ve used operator overloading (in C++) involved &#8220;normal&#8221; types that were wrapped in a class because they needed to be proxied somehow: atomic integers and pointers, byte-swapped integers, and objects in another address space which have to be accessed by DMA. (The last for the PS3 SPU.) All fine candidates for overloading.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rlw</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-159282</link>
		<dc:creator>rlw</dc:creator>
		<pubDate>Thu, 22 Nov 2007 18:52:15 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-159282</guid>
		<description>(% (/ banana knife) (+ milk cereal))</description>
		<content:encoded><![CDATA[<p>(% (/ banana knife) (+ milk cereal))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MikeN</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-156268</link>
		<dc:creator>MikeN</dc:creator>
		<pubDate>Fri, 16 Nov 2007 18:02:34 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-156268</guid>
		<description>Depriving users of a whole class of meaningful domain-specific function names because they are not alphanumeric seems a bit dogmatic. Software outgrew globally unique identifiers some time back.  On the other hand, adding operator overloading at this time to Java could only create confusion.
Look at Scala (scala-lang.org) for an elegant approach to operator overloading, coupled with serious type checking.</description>
		<content:encoded><![CDATA[<p>Depriving users of a whole class of meaningful domain-specific function names because they are not alphanumeric seems a bit dogmatic. Software outgrew globally unique identifiers some time back.  On the other hand, adding operator overloading at this time to Java could only create confusion.<br />
Look at Scala (scala-lang.org) for an elegant approach to operator overloading, coupled with serious type checking.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Werner Schulz</title>
		<link>http://cafe.elharo.com/blogroll/operator-overloading/#comment-151406</link>
		<dc:creator>Werner Schulz</dc:creator>
		<pubDate>Wed, 07 Nov 2007 19:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/operator-overloading/#comment-151406</guid>
		<description>It is most annoying that so many commentators here assume that those of us who want operator overloading are being assigned the worst-case examples like Michael Bar-Sinai's SpaceShuttle.+(GreenPeaSoup p). This is clear exaggeration. But even in more modest examples, like DateTime + DateTime, it is presumed that because operators are available the proponents of operators will use them while the equivalent DateTime.plus(DateTime) will never be written, of course, since the writers of such code are automatically soooo much sounder of mind! Nonsense.

In each case, you must come up with a sensible set of methods (once complete, consistent and well-defined you can even call it an algebra), give them proper names (plus or +, minus or -, ... whatever), implement and document them. In the end it remains a matter of style not substance, and I prefer the more concise mathematical operator. Let me have it.

In the end let the marketplace of ideas, of APIs decide which ones are being used by programmers, not some self-appointed style police.</description>
		<content:encoded><![CDATA[<p>It is most annoying that so many commentators here assume that those of us who want operator overloading are being assigned the worst-case examples like Michael Bar-Sinai&#8217;s SpaceShuttle.+(GreenPeaSoup p). This is clear exaggeration. But even in more modest examples, like DateTime + DateTime, it is presumed that because operators are available the proponents of operators will use them while the equivalent DateTime.plus(DateTime) will never be written, of course, since the writers of such code are automatically soooo much sounder of mind! Nonsense.</p>
<p>In each case, you must come up with a sensible set of methods (once complete, consistent and well-defined you can even call it an algebra), give them proper names (plus or +, minus or -, &#8230; whatever), implement and document them. In the end it remains a matter of style not substance, and I prefer the more concise mathematical operator. Let me have it.</p>
<p>In the end let the marketplace of ideas, of APIs decide which ones are being used by programmers, not some self-appointed style police.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
