<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Why Java doesn&#039;t need operator overloading (and very few languages do, really)</title>
	<atom:link href="http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/feed/" rel="self" type="application/rss+xml" />
	<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/</link>
	<description>Thoughts about software development</description>
	<lastBuildDate>Wed, 08 Sep 2010 15:33:13 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Neil Harding</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7442</link>
		<dc:creator>Neil Harding</dc:creator>
		<pubDate>Fri, 06 Nov 2009 06:28:55 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7442</guid>
		<description>I wrote a flight simulator for the Gameboy Advance, I used floats to test the math implementation (I declared all the variables as Fixed I typedef&#039;d it to be float during development). I could then use Fixed x = 0.1; x += velocityX * sin(angle) + velocityY * cos(angle), and I had sped up the game to 60 frames a second. I seriously abused C++ on game, it was converted from assembly language to C++ and there were byte ordering issues (big endian to little endian), so I defined unions .l .w .b and it would swap the bytes round on reading .l and writing it (using assembly language instruction to swap the order, so there was not too much penalty).</description>
		<content:encoded><![CDATA[<p>I wrote a flight simulator for the Gameboy Advance, I used floats to test the math implementation (I declared all the variables as Fixed I typedef&#8217;d it to be float during development). I could then use Fixed x = 0.1; x += velocityX * sin(angle) + velocityY * cos(angle), and I had sped up the game to 60 frames a second. I seriously abused C++ on game, it was converted from assembly language to C++ and there were byte ordering issues (big endian to little endian), so I defined unions .l .w .b and it would swap the bytes round on reading .l and writing it (using assembly language instruction to swap the order, so there was not too much penalty).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kishore</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7441</link>
		<dc:creator>kishore</dc:creator>
		<pubDate>Mon, 20 Jul 2009 01:26:19 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7441</guid>
		<description>In true object oriented sense i would expect to see state, behavior and i can&#039;t see that with operator overloading(it does kind of support polymorphism in some sense). I&#039;m not saying that overloading is not needed in java but may be the designers intention is to avoid confusion by keeping it close to object world. Over loading kind of breaks the abstraction.</description>
		<content:encoded><![CDATA[<p>In true object oriented sense i would expect to see state, behavior and i can&#8217;t see that with operator overloading(it does kind of support polymorphism in some sense). I&#8217;m not saying that overloading is not needed in java but may be the designers intention is to avoid confusion by keeping it close to object world. Over loading kind of breaks the abstraction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitko</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7440</link>
		<dc:creator>Mitko</dc:creator>
		<pubDate>Wed, 08 Jul 2009 09:37:40 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7440</guid>
		<description>Take examples from the natural origin of computer science: mathematics. Let&#039;s consider the multiplication operator. The operator has meaning for numbers, matrices, vectors with a number etc. In this case it is overloaded. What does it mean? This means that operator overloading makes sense in some cases. In Mathematics it is also strictly defined how the operators work, so that everyone knows what they mean and everyone is happy with them. In the world of programming languages overloading the operators makes sense when you design a DSL (Domain specific language). In the context of this language the operators will do what they are intended to do and what they are documented to do (hopefully). Java is not designed to be platform for DSLs, that could simplify the syntax of the code. Java is platform, not only a language, and it does a great job. Who will be the successor of Java is not so clear at the moment.</description>
		<content:encoded><![CDATA[<p>Take examples from the natural origin of computer science: mathematics. Let&#8217;s consider the multiplication operator. The operator has meaning for numbers, matrices, vectors with a number etc. In this case it is overloaded. What does it mean? This means that operator overloading makes sense in some cases. In Mathematics it is also strictly defined how the operators work, so that everyone knows what they mean and everyone is happy with them. In the world of programming languages overloading the operators makes sense when you design a DSL (Domain specific language). In the context of this language the operators will do what they are intended to do and what they are documented to do (hopefully). Java is not designed to be platform for DSLs, that could simplify the syntax of the code. Java is platform, not only a language, and it does a great job. Who will be the successor of Java is not so clear at the moment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kengkaj</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7439</link>
		<dc:creator>Kengkaj</dc:creator>
		<pubDate>Wed, 03 Jun 2009 07:50:35 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7439</guid>
		<description>I think the problem is not operator overloading per se, but abusing it can cause problem.
There is no different from normal Java method.
Like if we have method add, but when call it, it will read data from database and display it (not add anything), is Java method a problem?</description>
		<content:encoded><![CDATA[<p>I think the problem is not operator overloading per se, but abusing it can cause problem.<br />
There is no different from normal Java method.<br />
Like if we have method add, but when call it, it will read data from database and display it (not add anything), is Java method a problem?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bert</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7438</link>
		<dc:creator>Bert</dc:creator>
		<pubDate>Tue, 02 Jun 2009 16:16:27 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7438</guid>
		<description>Operator overloading might not seem to be a good idea outside arithmetics as a lot of people pointed out here. And C++ showed in a very bad way how this can be abused a lot (for a simple example just think about cout &lt;&lt; ... &lt;- now what this supposed to do ?)
But if you have to write software in the domain of arithmetics, for example 3D applications, cryptographic software, financial software or any kind of scientific software you are really missing operator overloading in Java a lot.
Just think about something like rendering algorithms (like raytracing, pathtracing, ambient occlusion and such stuff) where you have to compute the orthonormal base.
In a language with operator overloading you can write something like:
Vector3 d = (u * Math.Cos(r1) * r2s + v * Math.Sin(r1) * r2s + w * Math.Sqrt(1.0 - r2)).normalize();
in Java you would have to write something like
Vector3 d = ((u.vecsmul(Math.cos(r1) * r2s)).vecadd(v.vecmul(Math.sin(r1) * r2s)).vecadd(w.smul(Math.sqrt(1.0 - r2)))).normalize();
or when using static methods:
Vector3 d = (Vector3.vecadd(Vector3.vecadd(Vector3.vecsmul(u, Math.cos(r1) * r2s), Vector3.vecsmul(v, Math.sin(r1) * r2s)), Vector3.vecsmul(w, Math.sqrt(1.0 - f2)))).normalize();
or doing it the simple way:
Vector3 d = new Vector3();
d.x = (u.x * Math.Cos(r1) * r2s + v.x * Math.Sin(r1) * r2s + w.x * Math.Sqrt(1.0 - r2));
d.y = (u.y * Math.Cos(r1) * r2s + v.y * Math.Sin(r1) * r2s + w.y * Math.Sqrt(1.0 - r2));
d.z = (u.z * Math.Cos(r1) * r2s + v.z * Math.Sin(r1) * r2s + w.z * Math.Sqrt(1.0 - r2));
d.normalize();
This is just a tiny example. There are much more complicated formulas and things can really get nearly unreadable when it gets more complicated.
It can also be a source of errors when translating formulas from paper in your programming language since it is not easy to see on first sight if the translated formula is the same as on paper.
Another bad things when not having operator overloading in the language is that you have to memorize the function names for doing arithmetics.
So for arithmetic stuff like arbitrary-sized large integers (Bignum in java), Fractional (int/int) number representations, Base-10 floats for rounding issues (financial software), Arbitrary-precision floating-point numbers, complex numbers, quaternions, vectors, matrices and defining your own arithmetic for cryptography (like elliptic curves) i really miss operator overloading a lot in java. And for me it is really a reason not to use it for that kind of software.</description>
		<content:encoded><![CDATA[<p>Operator overloading might not seem to be a good idea outside arithmetics as a lot of people pointed out here. And C++ showed in a very bad way how this can be abused a lot (for a simple example just think about cout &lt;&lt; &#8230; &lt;- now what this supposed to do ?)<br />
But if you have to write software in the domain of arithmetics, for example 3D applications, cryptographic software, financial software or any kind of scientific software you are really missing operator overloading in Java a lot.<br />
Just think about something like rendering algorithms (like raytracing, pathtracing, ambient occlusion and such stuff) where you have to compute the orthonormal base.<br />
In a language with operator overloading you can write something like:<br />
Vector3 d = (u * Math.Cos(r1) * r2s + v * Math.Sin(r1) * r2s + w * Math.Sqrt(1.0 &#8211; r2)).normalize();<br />
in Java you would have to write something like<br />
Vector3 d = ((u.vecsmul(Math.cos(r1) * r2s)).vecadd(v.vecmul(Math.sin(r1) * r2s)).vecadd(w.smul(Math.sqrt(1.0 &#8211; r2)))).normalize();<br />
or when using static methods:<br />
Vector3 d = (Vector3.vecadd(Vector3.vecadd(Vector3.vecsmul(u, Math.cos(r1) * r2s), Vector3.vecsmul(v, Math.sin(r1) * r2s)), Vector3.vecsmul(w, Math.sqrt(1.0 &#8211; f2)))).normalize();<br />
or doing it the simple way:<br />
Vector3 d = new Vector3();<br />
d.x = (u.x * Math.Cos(r1) * r2s + v.x * Math.Sin(r1) * r2s + w.x * Math.Sqrt(1.0 &#8211; r2));<br />
d.y = (u.y * Math.Cos(r1) * r2s + v.y * Math.Sin(r1) * r2s + w.y * Math.Sqrt(1.0 &#8211; r2));<br />
d.z = (u.z * Math.Cos(r1) * r2s + v.z * Math.Sin(r1) * r2s + w.z * Math.Sqrt(1.0 &#8211; r2));<br />
d.normalize();<br />
This is just a tiny example. There are much more complicated formulas and things can really get nearly unreadable when it gets more complicated.<br />
It can also be a source of errors when translating formulas from paper in your programming language since it is not easy to see on first sight if the translated formula is the same as on paper.<br />
Another bad things when not having operator overloading in the language is that you have to memorize the function names for doing arithmetics.<br />
So for arithmetic stuff like arbitrary-sized large integers (Bignum in java), Fractional (int/int) number representations, Base-10 floats for rounding issues (financial software), Arbitrary-precision floating-point numbers, complex numbers, quaternions, vectors, matrices and defining your own arithmetic for cryptography (like elliptic curves) i really miss operator overloading a lot in java. And for me it is really a reason not to use it for that kind of software.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7437</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Sat, 23 May 2009 22:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7437</guid>
		<description>Paul:
&quot;&quot;&quot;
... elegant uses in Smalltalk:...
&quot;Yes fractions, making irrational numbers possible&quot;
3/7 + 5/6.
...
&quot;&quot;&quot;
But doesn&#039;t 3/7 + 5/6 in fact mean the same as (((3/7)+5)/6) in Smalltalk (left-to-right evaluation)? I think it does, and I think this an insane design decision - screwing up one of the two most useful applications of binary operators (the other one being comparison operators).
I think Scala does much better; precedence when using methods as binary operators is worked out from their names, in a way consistent with standard arithmetic.</description>
		<content:encoded><![CDATA[<p>Paul:<br />
&#8220;&#8221;"<br />
&#8230; elegant uses in Smalltalk:&#8230;<br />
&#8220;Yes fractions, making irrational numbers possible&#8221;<br />
3/7 + 5/6.<br />
&#8230;<br />
&#8220;&#8221;"<br />
But doesn&#8217;t 3/7 + 5/6 in fact mean the same as (((3/7)+5)/6) in Smalltalk (left-to-right evaluation)? I think it does, and I think this an insane design decision &#8211; screwing up one of the two most useful applications of binary operators (the other one being comparison operators).<br />
I think Scala does much better; precedence when using methods as binary operators is worked out from their names, in a way consistent with standard arithmetic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Isabelle Hawthorne</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7436</link>
		<dc:creator>Isabelle Hawthorne</dc:creator>
		<pubDate>Tue, 19 May 2009 01:36:33 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7436</guid>
		<description>The operators that I often want to overload and for which overloading allows the code to be very clear and readable are: ==, != and =. (i.e. equality, inequality and assignment). These three operators can be meaningfully, intuitively and usefully applied to any kind of object.</description>
		<content:encoded><![CDATA[<p>The operators that I often want to overload and for which overloading allows the code to be very clear and readable are: ==, != and =. (i.e. equality, inequality and assignment). These three operators can be meaningfully, intuitively and usefully applied to any kind of object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Beckford</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7435</link>
		<dc:creator>Paul Beckford</dc:creator>
		<pubDate>Mon, 20 Apr 2009 02:51:38 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7435</guid>
		<description>Quickly flicked through this, and absolutely no one has offered any of the numerous elegant uses in Smalltalk:
Off the top of my head how about these for starters:
&quot;Yes fractions, making irrational numbers possible&quot;
3/7  + 5/6.
&quot;How about complex numbers anyone?&quot;
(2 +3i)
&quot;Ever wanted to send several messages to the same object?&quot;
receiver doThis, andThis, andAlsoThis.
Thats before we get to advance uses like this  BNF expressed in Newspeak:
id = letter, (letter &#124; digit) star.
I just don&#039;t understand how people adopt such strong views, based on such limited experience. Yes I do. We all love the comfort you get from saying &quot;I Know It Already&quot;, even when we possibly don&#039;t.
Ah, well such is human nature :)</description>
		<content:encoded><![CDATA[<p>Quickly flicked through this, and absolutely no one has offered any of the numerous elegant uses in Smalltalk:<br />
Off the top of my head how about these for starters:<br />
&#8220;Yes fractions, making irrational numbers possible&#8221;<br />
3/7  + 5/6.<br />
&#8220;How about complex numbers anyone?&#8221;<br />
(2 +3i)<br />
&#8220;Ever wanted to send several messages to the same object?&#8221;<br />
receiver doThis, andThis, andAlsoThis.<br />
Thats before we get to advance uses like this  BNF expressed in Newspeak:<br />
id = letter, (letter | digit) star.<br />
I just don&#8217;t understand how people adopt such strong views, based on such limited experience. Yes I do. We all love the comfort you get from saying &#8220;I Know It Already&#8221;, even when we possibly don&#8217;t.<br />
Ah, well such is human nature <img src='http://beust.com/weblog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sony Mathew</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7434</link>
		<dc:creator>Sony Mathew</dc:creator>
		<pubDate>Tue, 14 Apr 2009 18:26:54 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7434</guid>
		<description>As one that may have abused operator overloading in my past C++ days (never been accused) - I find them very handy.  To me they are no worse than a badly documented method - meaning operator+(Object obj) is no different than add(Object obj) method - its all in the consistent contract it defines and enforces.</description>
		<content:encoded><![CDATA[<p>As one that may have abused operator overloading in my past C++ days (never been accused) &#8211; I find them very handy.  To me they are no worse than a badly documented method &#8211; meaning operator+(Object obj) is no different than add(Object obj) method &#8211; its all in the consistent contract it defines and enforces.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rssh</title>
		<link>http://beust.com/weblog/2009/04/12/why-java-doesnt-need-operator-overloading-and-very-few-languages-do-really/comment-page-1/#comment-7433</link>
		<dc:creator>rssh</dc:creator>
		<pubDate>Tue, 14 Apr 2009 15:14:56 +0000</pubDate>
		<guid isPermaLink="false">http://beust.com/weblog/?p=519#comment-7433</guid>
		<description>) I would love to see some good examples of operator overloading, if you have any to share...
BigDecimal, Matrices, Measurements, Money
I can&#039;t understand why you speak about Collections. Of course arithmetic operator overloading in Collections is not good idea ;)
But having some analog of operator []= for user-defined classes can be useful.
(And as I understand from project coin, java 7 will have overloaded array index access for collections)</description>
		<content:encoded><![CDATA[<p>) I would love to see some good examples of operator overloading, if you have any to share&#8230;<br />
BigDecimal, Matrices, Measurements, Money<br />
I can&#8217;t understand why you speak about Collections. Of course arithmetic operator overloading in Collections is not good idea <img src='http://beust.com/weblog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
But having some analog of operator []= for user-defined classes can be useful.<br />
(And as I understand from project coin, java 7 will have overloaded array index access for collections)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
