<?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: Type Inference: Another Bad Idea for Java 7</title>
	<atom:link href="http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/</link>
	<description>Longer than a blog; shorter than a book</description>
	<pubDate>Tue, 06 Jan 2009 13:19:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Rob Griffin</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-262840</link>
		<dc:creator>Rob Griffin</dc:creator>
		<pubDate>Fri, 15 Aug 2008 03:31:58 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-262840</guid>
		<description>&lt;blockquote&gt;
but double writing for type-paramters sucks
&lt;/blockquote&gt;

If you use Eclipse then you never need to type the type-parameters more than once; Eclipse's code completion fills them in for you. I would image (or hope) that other IDEs can do the same.

At the moment I'm doing a bit of C# which supports duck typing using the var keyword. I don't like it much because if the variable is being returned by a method you can't readily see the type.

E.g.
   var x = getClients();

What type is x? Also the IDE can no longer go to the definition of the type because var is a keyword.

In Java I use Eclipse to do the work for me; quick fix can create a variable to hold the return value of a method and guess a name based on the method name e.g. the quick fix 'Assign statement to new local variable' on getClients() will result in a variable called clients of the type returned by the method. 

So I think the answer is to use the right tools. No language changes are required .</description>
		<content:encoded><![CDATA[<blockquote><p>
but double writing for type-paramters sucks
</p></blockquote>
<p>If you use Eclipse then you never need to type the type-parameters more than once; Eclipse&#8217;s code completion fills them in for you. I would image (or hope) that other IDEs can do the same.</p>
<p>At the moment I&#8217;m doing a bit of C# which supports duck typing using the var keyword. I don&#8217;t like it much because if the variable is being returned by a method you can&#8217;t readily see the type.</p>
<p>E.g.<br />
   var x = getClients();</p>
<p>What type is x? Also the IDE can no longer go to the definition of the type because var is a keyword.</p>
<p>In Java I use Eclipse to do the work for me; quick fix can create a variable to hold the return value of a method and guess a name based on the method name e.g. the quick fix &#8216;Assign statement to new local variable&#8217; on getClients() will result in a variable called clients of the type returned by the method. </p>
<p>So I think the answer is to use the right tools. No language changes are required .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emanuel</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-100636</link>
		<dc:creator>emanuel</dc:creator>
		<pubDate>Tue, 12 Jun 2007 13:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-100636</guid>
		<description>&lt;blockquote&gt;
Further, nobody will argue against that:
final Map map = new HashMap();
is a better coding style than:
final HashMap map = new HashMap();
&lt;/blockquote&gt;

Well, I just did argue against it. See entry just above yours.
Here some more reasons: you also don't write:

Number n1 = 3;
Number n2 = 3.7;
CharSequence s = "hi";

If you don't care about the precise type then use a scripting language, but not Java.</description>
		<content:encoded><![CDATA[<blockquote><p>
Further, nobody will argue against that:<br />
final Map map = new HashMap();<br />
is a better coding style than:<br />
final HashMap map = new HashMap();
</p></blockquote>
<p>Well, I just did argue against it. See entry just above yours.<br />
Here some more reasons: you also don&#8217;t write:</p>
<p>Number n1 = 3;<br />
Number n2 = 3.7;<br />
CharSequence s = &#8220;hi&#8221;;</p>
<p>If you don&#8217;t care about the precise type then use a scripting language, but not Java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Nischt</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-100335</link>
		<dc:creator>Michael Nischt</dc:creator>
		<pubDate>Mon, 11 Jun 2007 12:28:56 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-100335</guid>
		<description>In principle I like that everything is final by default or the nicer syntax  with the special operator ':='. However, I agree it would mess up Java's style.
Further, nobody will argue against that:
final Map&#60;String, Integer&#62; map = new HashMap&#60;String, Integer&#62;();
is a better coding style than:
final HashMap&#60;String, Integer&#62; map = new HashMap&#60;String, Integer&#62;();
Which why I'm also against:
final map = new HashMap&#60;String, Integer&#62;();
IMHO, specifying types is not the problem, but double writing for &lt;i&gt;type-paramters&lt;/i&gt; sucks. This is why I'd like to see an automatic generation of an overloaded new-method for each constructor:
final Map&#60;String, Integer&#62; map = HashMap.new();

Besides, that 'new' is a reserved keyword, one could also do that by hand and the &lt;i&gt;type-paramters&lt;/i&gt; would be inferred whenever possible. Luckily this makes 'new' an ideal candidate for a language addition :-)</description>
		<content:encoded><![CDATA[<p>In principle I like that everything is final by default or the nicer syntax  with the special operator &#8216;:=&#8217;. However, I agree it would mess up Java&#8217;s style.<br />
Further, nobody will argue against that:<br />
final Map&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();<br />
is a better coding style than:<br />
final HashMap&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();<br />
Which why I&#8217;m also against:<br />
final map = new HashMap&lt;String, Integer&gt;();<br />
IMHO, specifying types is not the problem, but double writing for <i>type-paramters</i> sucks. This is why I&#8217;d like to see an automatic generation of an overloaded new-method for each constructor:<br />
final Map&lt;String, Integer&gt; map = HashMap.new();</p>
<p>Besides, that &#8216;new&#8217; is a reserved keyword, one could also do that by hand and the <i>type-paramters</i> would be inferred whenever possible. Luckily this makes &#8216;new&#8217; an ideal candidate for a language addition <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emanuel</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-99435</link>
		<dc:creator>emanuel</dc:creator>
		<pubDate>Fri, 08 Jun 2007 17:46:06 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-99435</guid>
		<description>Interfaces like Map and List make sense as parameter types for public API method declarations, but not for local or private code/declarations. And also not for public API method return types.

The statement that the local declaration &lt;code&gt;List list = new ArrayList();&lt;/code&gt; allows to use any kind of list is wrong:

you have to change the code exactly there where it is used:&lt;code&gt;List list = new LinkedList();&lt;/code&gt;
just look into the JDK collection API documentation how often Sun changes the semantic of overwritten methods. Example: Collection.add(Object) adds element anywhere while List.add(Object) specifies it to &lt;b&gt;append&lt;/b&gt; the element. Not to mention that in both cases add(Object) is an optional method, which your code then should not use if it should be able to deal with any List implementation.
even if the semantic remains the same when switching to a java.util.LinkedList, you will not want to write e.g.  &lt;code&gt;for( int i = 0; i  but use an iterator instead, because indexing in linked lists is horrible slow.

Again: using interfaces instead of real classes makes sense for public API but not for local or private code.

And as shown in the above list in most cases it is even important to know whether some code is dealing with an ArrayList or with a LinkedList. And not only at the location where the variable was initialized.</description>
		<content:encoded><![CDATA[<p>Interfaces like Map and List make sense as parameter types for public API method declarations, but not for local or private code/declarations. And also not for public API method return types.</p>
<p>The statement that the local declaration <code>List list = new ArrayList();</code> allows to use any kind of list is wrong:</p>
<p>you have to change the code exactly there where it is used:<code>List list = new LinkedList();</code><br />
just look into the JDK collection API documentation how often Sun changes the semantic of overwritten methods. Example: Collection.add(Object) adds element anywhere while List.add(Object) specifies it to <b>append</b> the element. Not to mention that in both cases add(Object) is an optional method, which your code then should not use if it should be able to deal with any List implementation.<br />
even if the semantic remains the same when switching to a java.util.LinkedList, you will not want to write e.g.  <code>for( int i = 0; i  but use an iterator instead, because indexing in linked lists is horrible slow.</p>
<p>Again: using interfaces instead of real classes makes sense for public API but not for local or private code.</p>
<p>And as shown in the above list in most cases it is even important to know whether some code is dealing with an ArrayList or with a LinkedList. And not only at the location where the variable was initialized.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-92275</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 22 May 2007 07:24:32 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-92275</guid>
		<description>I really don't like all the JCP proposals to add dynamic language features like type inference and closures by making the language more confusing and totally ignoring the core philosophies behind Java.  This one, and all but CICE, make the language more complex and unreadable.  If I wanted a language where everyone threw in every fad idea they could think of, I'd be writtting in C++.

Personally, the feature I'd like to see added is Design-by-Contract similar to how Eiffel does it.  I think it would be in line with the core principles of Java and greatly improve readability / robustness of code.  Being able to define a contract in the interface and know that every implementor abides by it is simply strengthening current practices.  And if it did cause enough of a performance problem (not likely, especially when RoR is the rage and is dog slow) it can be turned off for production but help detect errors early in QA cycles.

All the features that Java-5 added I use every day, but I rarely find myself wanting any of the ones proposed for Java-7.  When I read the blogs of those who propose the additions (like Gafter's and Colebourne's) its obvious they're lost over-designing than dealing with real-world scenarios.  I'd rather see Colebourne focus on cleaning up Joda Time for the JDK than screw around with another ugly closure implementation.</description>
		<content:encoded><![CDATA[<p>I really don&#8217;t like all the JCP proposals to add dynamic language features like type inference and closures by making the language more confusing and totally ignoring the core philosophies behind Java.  This one, and all but CICE, make the language more complex and unreadable.  If I wanted a language where everyone threw in every fad idea they could think of, I&#8217;d be writtting in C++.</p>
<p>Personally, the feature I&#8217;d like to see added is Design-by-Contract similar to how Eiffel does it.  I think it would be in line with the core principles of Java and greatly improve readability / robustness of code.  Being able to define a contract in the interface and know that every implementor abides by it is simply strengthening current practices.  And if it did cause enough of a performance problem (not likely, especially when RoR is the rage and is dog slow) it can be turned off for production but help detect errors early in QA cycles.</p>
<p>All the features that Java-5 added I use every day, but I rarely find myself wanting any of the ones proposed for Java-7.  When I read the blogs of those who propose the additions (like Gafter&#8217;s and Colebourne&#8217;s) its obvious they&#8217;re lost over-designing than dealing with real-world scenarios.  I&#8217;d rather see Colebourne focus on cleaning up Joda Time for the JDK than screw around with another ugly closure implementation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Augusto</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-80403</link>
		<dc:creator>Augusto</dc:creator>
		<pubDate>Mon, 23 Apr 2007 04:47:51 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-80403</guid>
		<description>Thanks for those links, had no ideas these features were being added to C++.

It would be ironic if C++ gets closures while Java doesn't ...</description>
		<content:encoded><![CDATA[<p>Thanks for those links, had no ideas these features were being added to C++.</p>
<p>It would be ironic if C++ gets closures while Java doesn&#8217;t &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Eccardt</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-80349</link>
		<dc:creator>Robert Eccardt</dc:creator>
		<pubDate>Sun, 22 Apr 2007 23:08:33 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-80349</guid>
		<description>In actual use, I don't think it will matter much that the inferred type will be the exact type of what was assigned to it.  It is not seen in the code and it can be used as if it were the interface type the programmer had in mind. When we say

Map m = new HashMap();

we know the underlying object in m is a HashMap anyway.  By not making any kind of explicit type declaration at all for m, the best practice of always making the reference the least specific possible becomes moot.

Even venerable old C++ is adding features, including type inference.  In this article from over a year ago,  Bjarne Stroustrup outlines the new features (they'll use the keyword "auto" for type inference):

http://www.artima.com/cppsource/cpp0x.html

And this is Stroustrup's proposal for lambda expressions and closures in C++:

http://public.research.att.com/%7Ebs/N1968-lambda-expressions.pdf</description>
		<content:encoded><![CDATA[<p>In actual use, I don&#8217;t think it will matter much that the inferred type will be the exact type of what was assigned to it.  It is not seen in the code and it can be used as if it were the interface type the programmer had in mind. When we say</p>
<p>Map m = new HashMap();</p>
<p>we know the underlying object in m is a HashMap anyway.  By not making any kind of explicit type declaration at all for m, the best practice of always making the reference the least specific possible becomes moot.</p>
<p>Even venerable old C++ is adding features, including type inference.  In this article from over a year ago,  Bjarne Stroustrup outlines the new features (they&#8217;ll use the keyword &#8220;auto&#8221; for type inference):</p>
<p><a href="http://www.artima.com/cppsource/cpp0x.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.artima.com');" rel="nofollow">http://www.artima.com/cppsource/cpp0x.html</a></p>
<p>And this is Stroustrup&#8217;s proposal for lambda expressions and closures in C++:</p>
<p><a href="http://public.research.att.com/%7Ebs/N1968-lambda-expressions.pdf" onclick="javascript:pageTracker._trackPageview('/outbound/comment/public.research.att.com');" rel="nofollow">http://public.research.att.com/%7Ebs/N1968-lambda-expressions.pdf</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: musaddi</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-80257</link>
		<dc:creator>musaddi</dc:creator>
		<pubDate>Sun, 22 Apr 2007 15:04:33 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-80257</guid>
		<description>public Map foo() {
   final map = new HashMap();
   ...
   return map;
}

this is understood by the compiler as HashMap. What's the problem with that. Why do you want

Map map = new HashMap();

Probably you want to be able to change that to TreeMap later on. 
But you could do that, even with the above one. When you want it to be assigned to a Map reference you could always do that.For example you could return it as a Map. 
Want to change it to TreeMap? No problem change it. That's ok. And if it is not compatible, compiler detects it.
For eg. 
public Map foo() {
   final map = new TreeMap();
   ...
   return map;
}

Am I missing something?</description>
		<content:encoded><![CDATA[<p>public Map foo() {<br />
   final map = new HashMap();<br />
   &#8230;<br />
   return map;<br />
}</p>
<p>this is understood by the compiler as HashMap. What&#8217;s the problem with that. Why do you want</p>
<p>Map map = new HashMap();</p>
<p>Probably you want to be able to change that to TreeMap later on.<br />
But you could do that, even with the above one. When you want it to be assigned to a Map reference you could always do that.For example you could return it as a Map.<br />
Want to change it to TreeMap? No problem change it. That&#8217;s ok. And if it is not compatible, compiler detects it.<br />
For eg.<br />
public Map foo() {<br />
   final map = new TreeMap();<br />
   &#8230;<br />
   return map;<br />
}</p>
<p>Am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Masklinn</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-80191</link>
		<dc:creator>Masklinn</dc:creator>
		<pubDate>Sun, 22 Apr 2007 11:22:28 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-80191</guid>
		<description>&lt;blockquote&gt;

I canâ€™t understand. For me, the compiler always will understand

final map = new HashMap();

as

HashMap map = new HashMap();

If you want Map or another interface, you must explicit it:

Map map = new HashMap();&lt;/blockquote&gt;
As I mentioned, it has no reason whatsoever to work that way, using the context of this code (the way you're using &lt;code&gt;map&lt;/code&gt;) allows the compiler to infer the most possibly abstract types (in this case, there's no reason why it couldn't infer that &lt;code&gt;map&lt;/code&gt; is of type &lt;code&gt;Map&lt;/code&gt;). Moreover, since type inference requires an extremely extensive static type analysis (and the less formalized the type system, the more extensive the analysis requirements) the compiler would be able to warn you in case of inference to concrete datatypes (what ZdenÄ›k MachaÄ gave an example of, in his own example it's impossible for the compiler to infer to an ADTs because the code only works on a specific, concrete datatype).</description>
		<content:encoded><![CDATA[<blockquote>
<p>I canâ€™t understand. For me, the compiler always will understand</p>
<p>final map = new HashMap();</p>
<p>as</p>
<p>HashMap map = new HashMap();</p>
<p>If you want Map or another interface, you must explicit it:</p>
<p>Map map = new HashMap();</p></blockquote>
<p>As I mentioned, it has no reason whatsoever to work that way, using the context of this code (the way you&#8217;re using <code>map</code>) allows the compiler to infer the most possibly abstract types (in this case, there&#8217;s no reason why it couldn&#8217;t infer that <code>map</code> is of type <code>Map</code>). Moreover, since type inference requires an extremely extensive static type analysis (and the less formalized the type system, the more extensive the analysis requirements) the compiler would be able to warn you in case of inference to concrete datatypes (what ZdenÄ›k MachaÄ gave an example of, in his own example it&#8217;s impossible for the compiler to infer to an ADTs because the code only works on a specific, concrete datatype).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Parker</title>
		<link>http://cafe.elharo.com/blogroll/type-inference-another-bad-idea-for-java-7/#comment-79415</link>
		<dc:creator>Peter Parker</dc:creator>
		<pubDate>Fri, 20 Apr 2007 14:39:04 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/type-inference-another-bad-idea-for-java-7/#comment-79415</guid>
		<description>I can't understand. For me, the compiler always will understand 

final map = new HashMap();

as 

HashMap map = new HashMap();

If you want Map or another interface, you must explicit it:

Map map = new HashMap();

Clear enough, ah?</description>
		<content:encoded><![CDATA[<p>I can&#8217;t understand. For me, the compiler always will understand </p>
<p>final map = new HashMap();</p>
<p>as </p>
<p>HashMap map = new HashMap();</p>
<p>If you want Map or another interface, you must explicit it:</p>
<p>Map map = new HashMap();</p>
<p>Clear enough, ah?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
