<?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: Java Needs Map Syntax Sugar</title>
	<atom:link href="http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:21:24 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Peter</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-4932</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 05 Feb 2010 08:41:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-4932</guid>
		<description>Just create class: 
public class SSMap extends HashMap {

	private static final long serialVersionUID = 1L;

	public SSMap i(String key, String value) {
		this.put(key, value);
		return this;
	}
	
}


and then:



		SSMap params = new SSMap()
			.i(&quot;idSite&quot;, &quot;1&quot;)
			.i(&quot;period&quot;, &quot;day&quot;)
			.i(&quot;date&quot;, &quot;today&quot;);</description>
		<content:encoded><![CDATA[<p>Just create class:<br />
public class SSMap extends HashMap {</p>
<p>	private static final long serialVersionUID = 1L;</p>
<p>	public SSMap i(String key, String value) {<br />
		this.put(key, value);<br />
		return this;<br />
	}</p>
<p>}</p>
<p>and then:</p>
<p>		SSMap params = new SSMap()<br />
			.i(&#8220;idSite&#8221;, &#8220;1&#8243;)<br />
			.i(&#8220;period&#8221;, &#8220;day&#8221;)<br />
			.i(&#8220;date&#8221;, &#8220;today&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2720</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Tue, 22 Jan 2008 07:38:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2720</guid>
		<description>See 

http://gleichmann.wordpress.com/2008/01/15/building-your-own-literals-in-java-tuples-and-maps/

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>See </p>
<p><a href="http://gleichmann.wordpress.com/2008/01/15/building-your-own-literals-in-java-tuples-and-maps/" rel="nofollow">http://gleichmann.wordpress.com/2008/01/15/building-your-own-literals-in-java-tuples-and-maps/</a></p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2591</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Wed, 19 Dec 2007 19:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2591</guid>
		<description>In such a case where there is ambiguity (such as the two Map instance), the syntax could only be used for the latter Map.  This isn&#039;t entirely without precedence in Java, where we have some nice(?) syntactic sugar for varargs, but only on the last parameter of the method.</description>
		<content:encoded><![CDATA[<p>In such a case where there is ambiguity (such as the two Map instance), the syntax could only be used for the latter Map.  This isn&#8217;t entirely without precedence in Java, where we have some nice(?) syntactic sugar for varargs, but only on the last parameter of the method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: svenmeier</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2590</link>
		<dc:creator>svenmeier</dc:creator>
		<pubDate>Wed, 19 Dec 2007 12:55:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2590</guid>
		<description>I can&#039;t disagree more.

&gt;Many methods these days take a Map as a parameter

Well, I&#039;d call an API with such methods a bad API. Why not defined some constants while you&#039;re at it:

public static final String FIRST_NAME = &quot;firstName&quot;;

Bah.

&gt;Person person = em.create(Person.class, &quot;firstName&quot;:&quot;daniel&quot;, &quot;lastName&quot;:&quot;Spiewak&quot;);

What if the create method takes two maps as arguments create(Class clazz, Map mapA, Map mapB)?
I don&#039;t know how Ruby does it but how should Java be able to sort out which values belong to which parameter?</description>
		<content:encoded><![CDATA[<p>I can&#8217;t disagree more.</p>
<p>&gt;Many methods these days take a Map as a parameter</p>
<p>Well, I&#8217;d call an API with such methods a bad API. Why not defined some constants while you&#8217;re at it:</p>
<p>public static final String FIRST_NAME = &#8220;firstName&#8221;;</p>
<p>Bah.</p>
<p>&gt;Person person = em.create(Person.class, &#8220;firstName&#8221;:&#8221;daniel&#8221;, &#8220;lastName&#8221;:&#8221;Spiewak&#8221;);</p>
<p>What if the create method takes two maps as arguments create(Class clazz, Map mapA, Map mapB)?<br />
I don&#8217;t know how Ruby does it but how should Java be able to sort out which values belong to which parameter?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Colebourne</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2589</link>
		<dc:creator>Stephen Colebourne</dc:creator>
		<pubDate>Tue, 18 Dec 2007 23:25:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2589</guid>
		<description>If you want to implement it in javac, the Kijaro project is the place to go, not the KSL - https://kijaro.dev.java.net/</description>
		<content:encoded><![CDATA[<p>If you want to implement it in javac, the Kijaro project is the place to go, not the KSL &#8211; <a href="https://kijaro.dev.java.net/" rel="nofollow">https://kijaro.dev.java.net/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael B</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2588</link>
		<dc:creator>Michael B</dc:creator>
		<pubDate>Tue, 18 Dec 2007 22:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2588</guid>
		<description>What this is actually doing is declaring a constructor for an anonymous inner class extending HashMap.

A InstanceInitializer isn&#039;t a Constructor. http://java.sun.com/docs/books/jls/third_edition/html/classes.html#246032

And I wouldn&#039;t call it a shorthand notation it does what you declare it to do in the order that you declare it should be done and there is no long form that is truely equal. (sure there are ways that the result will be the same but the execution is/operations are different.) (step 4 in paragraph 12.5 for execution order) (For the ppl that had there cup of coffee: pls note how if there wouldn&#039;t be subclass beeing created here you would get a runtime error ;-)

to dive into the actual discussion; I wouldn&#039;t call the ruby bit cleaner, shorter? yes, less effort? yes, easier to read? if you say so.  Sure the java syntax is a bit painful I agree. Also the problem isn&#039;t limited to maps alone.  Think other containers like (J)Component&#039;s but also simple Lists. Now one option for that was to make add() methods return the object your adding to allowing for:

Container container = new Container();
container.add(foo)
.add(bar)
.add(ducky)
.add(firetruck);

(someone even suggested that void could be implicitly return the object which the method belongs to)
But any add()-alike method might return at this time something else like the status of the operation or other stuff. But it falls more into api-design then language-design I guess.

you asking for a (shorthand) syntax to create Map.Entry and implicitly wrap those in a Map which is where the problems start. The later(implicitly wrapping) creates unreadable bit&#039;s of code. What if em.create() takes 3 arguments Type Map and something else(heaven forbit: a Map). Sure you can get around that by using the same restrictions as Object... object has. but that has it&#039;s drawbacks too.

now you can hope for something alike (please ignore that Map is an interface, I suppose you could use Unmodifiable map)
Person person = em.create(Person.class, new Map(&quot;firstName&quot;:&quot;daniel&quot;, &quot;lastName&quot;:&quot;Spiewak&quot;));
Person person = em.create(Person.class, Collections.unmodifiableMap(&quot;firstName&quot;:&quot;daniel&quot;, &quot;lastName&quot;:&quot;Spiewak&quot;));
I gues you see the drawbacks of that too.

JDBC is low level, also in general java developers don&#039;t like collections with unenforced rules to masquerade as types. Which is where script-like languages and java-like languages clash. Sure creating shorthand constructions for data objects is tedious. Illustration:

Person person = new Person();
person.setFirstName(&quot;Michael&quot;);
person.setLastName(&quot;B&quot;);

person = em.persist(person);

vs

Person person = new Person(&quot;Michael&quot;,&quot;b&quot;);
person = em.persist(person);

(+ creating dull constructors)
causes problems if &#039;shorthand&#039; constructors end up having the same type arguments.

Here &#039;named parameters&#039;-constructors for beans that can be and should be auto-generated could be a blessing:

(Person is a bean)
Person person = new Person(FirstName:&quot;Michael&quot;,LastName:&quot;B&quot;);
person = em.persist(person);

Person person = new Person(LastName:&quot;B&quot;,Foo:&quot;bar&quot;);
person = em.persist(person);

Some other notes:
I wouldn&#039;t know about inconsistency but if you referencing to verbose as bulky then I like bulky and it would be intentionally bulky.

Also generics was introduced to improve type safety not as syntax sugar.</description>
		<content:encoded><![CDATA[<p>What this is actually doing is declaring a constructor for an anonymous inner class extending HashMap.</p>
<p>A InstanceInitializer isn&#8217;t a Constructor. <a href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#246032" rel="nofollow">http://java.sun.com/docs/books/jls/third_edition/html/classes.html#246032</a></p>
<p>And I wouldn&#8217;t call it a shorthand notation it does what you declare it to do in the order that you declare it should be done and there is no long form that is truely equal. (sure there are ways that the result will be the same but the execution is/operations are different.) (step 4 in paragraph 12.5 for execution order) (For the ppl that had there cup of coffee: pls note how if there wouldn&#8217;t be subclass beeing created here you would get a runtime error <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>to dive into the actual discussion; I wouldn&#8217;t call the ruby bit cleaner, shorter? yes, less effort? yes, easier to read? if you say so.  Sure the java syntax is a bit painful I agree. Also the problem isn&#8217;t limited to maps alone.  Think other containers like (J)Component&#8217;s but also simple Lists. Now one option for that was to make add() methods return the object your adding to allowing for:</p>
<p>Container container = new Container();<br />
container.add(foo)<br />
.add(bar)<br />
.add(ducky)<br />
.add(firetruck);</p>
<p>(someone even suggested that void could be implicitly return the object which the method belongs to)<br />
But any add()-alike method might return at this time something else like the status of the operation or other stuff. But it falls more into api-design then language-design I guess.</p>
<p>you asking for a (shorthand) syntax to create Map.Entry and implicitly wrap those in a Map which is where the problems start. The later(implicitly wrapping) creates unreadable bit&#8217;s of code. What if em.create() takes 3 arguments Type Map and something else(heaven forbit: a Map). Sure you can get around that by using the same restrictions as Object&#8230; object has. but that has it&#8217;s drawbacks too.</p>
<p>now you can hope for something alike (please ignore that Map is an interface, I suppose you could use Unmodifiable map)<br />
Person person = em.create(Person.class, new Map(&#8220;firstName&#8221;:&#8221;daniel&#8221;, &#8220;lastName&#8221;:&#8221;Spiewak&#8221;));<br />
Person person = em.create(Person.class, Collections.unmodifiableMap(&#8220;firstName&#8221;:&#8221;daniel&#8221;, &#8220;lastName&#8221;:&#8221;Spiewak&#8221;));<br />
I gues you see the drawbacks of that too.</p>
<p>JDBC is low level, also in general java developers don&#8217;t like collections with unenforced rules to masquerade as types. Which is where script-like languages and java-like languages clash. Sure creating shorthand constructions for data objects is tedious. Illustration:</p>
<p>Person person = new Person();<br />
person.setFirstName(&#8220;Michael&#8221;);<br />
person.setLastName(&#8220;B&#8221;);</p>
<p>person = em.persist(person);</p>
<p>vs</p>
<p>Person person = new Person(&#8220;Michael&#8221;,&#8221;b&#8221;);<br />
person = em.persist(person);</p>
<p>(+ creating dull constructors)<br />
causes problems if &#8217;shorthand&#8217; constructors end up having the same type arguments.</p>
<p>Here &#8216;named parameters&#8217;-constructors for beans that can be and should be auto-generated could be a blessing:</p>
<p>(Person is a bean)<br />
Person person = new Person(FirstName:&#8221;Michael&#8221;,LastName:&#8221;B&#8221;);<br />
person = em.persist(person);</p>
<p>Person person = new Person(LastName:&#8221;B&#8221;,Foo:&#8221;bar&#8221;);<br />
person = em.persist(person);</p>
<p>Some other notes:<br />
I wouldn&#8217;t know about inconsistency but if you referencing to verbose as bulky then I like bulky and it would be intentionally bulky.</p>
<p>Also generics was introduced to improve type safety not as syntax sugar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nir Tayeb</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2587</link>
		<dc:creator>Nir Tayeb</dc:creator>
		<pubDate>Tue, 18 Dec 2007 20:55:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2587</guid>
		<description>if you want dynamic operations like key:value assignment, use groovy, else use Java
you can use them together, all groovy objects are Java objects too.
You can use also the JavaFX Script and it&#039;s structured style code, it&#039;s also same as groovy, JavaFX&#039;s objects are Java objects too.</description>
		<content:encoded><![CDATA[<p>if you want dynamic operations like key:value assignment, use groovy, else use Java<br />
you can use them together, all groovy objects are Java objects too.<br />
You can use also the JavaFX Script and it&#8217;s structured style code, it&#8217;s also same as groovy, JavaFX&#8217;s objects are Java objects too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Weiskotten</title>
		<link>http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar/comment-page-1#comment-2586</link>
		<dc:creator>Jeremy Weiskotten</dc:creator>
		<pubDate>Tue, 18 Dec 2007 20:05:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/java/java-needs-map-syntax-sugar#comment-2586</guid>
		<description>I don&#039;t think Java &quot;needs&quot; it, but I agree: Java would benefit from some syntactic sugar around HashMap. It&#039;s not without precedence; consider the syntactic sugar around String.

Ruby&#039;s hash syntax is excellent, and greatly influences APIs built with Ruby, including many of the Rails APIs. The simple hash syntax basically gives you a simple form of named arguments, which can be used to make a very powerful, but easy-to-use, API, because you don&#039;t have to pass arguments in a specific order, and you can better grok a method call without looking up its definition.

Of course, closures have an even bigger impact on APIs. :)

Even the following example, which is a bit less of a leap from Java in its current form, would be a big improvement:

    Person person = em.create(Person.class, new HashMap(&quot;firstName&quot;:&quot;daniel&quot;, &quot;lastName&quot;:&quot;Spiewak&quot;));

...Although I think I prefer Ruby&#039;s =&gt; notation to the colon notation you&#039;ve borrowed from Groovy.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think Java &#8220;needs&#8221; it, but I agree: Java would benefit from some syntactic sugar around HashMap. It&#8217;s not without precedence; consider the syntactic sugar around String.</p>
<p>Ruby&#8217;s hash syntax is excellent, and greatly influences APIs built with Ruby, including many of the Rails APIs. The simple hash syntax basically gives you a simple form of named arguments, which can be used to make a very powerful, but easy-to-use, API, because you don&#8217;t have to pass arguments in a specific order, and you can better grok a method call without looking up its definition.</p>
<p>Of course, closures have an even bigger impact on APIs. <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Even the following example, which is a bit less of a leap from Java in its current form, would be a big improvement:</p>
<p>    Person person = em.create(Person.class, new HashMap(&#8220;firstName&#8221;:&#8221;daniel&#8221;, &#8220;lastName&#8221;:&#8221;Spiewak&#8221;));</p>
<p>&#8230;Although I think I prefer Ruby&#8217;s =&gt; notation to the colon notation you&#8217;ve borrowed from Groovy.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

