<?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: Caller context and list.add(..).add(..).add(..)</title>
	<atom:link href="http://almaer.com/blog/caller-context-and-listaddaddadd/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog/caller-context-and-listaddaddadd</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Sat, 08 Sep 2012 07:06:53 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Helly</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22464</link>
		<dc:creator>Helly</dc:creator>
		<pubDate>Fri, 02 Jun 2006 23:49:21 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22464</guid>
		<description>captive
</description>
		<content:encoded><![CDATA[<p>captive</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Dennis</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22463</link>
		<dc:creator>Greg Dennis</dc:creator>
		<pubDate>Fri, 15 Apr 2005 22:40:46 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22463</guid>
		<description>I think chained-methods are nice and useful, but they give the impression that the object is immutable -- that it has to return a new instance rather than perform a mutation. The last thing you want is for clients not to realize they are mutating an object when they are. I would recommend using chained methods if and only if the object is immutable.

If there&#039;s one exception, it&#039;s StringBuffer, because (1) it&#039;s used so frequently; (2) it so significantly reduces the amount of code; and (3) it&#039;s very well known that it&#039;s mutable.
</description>
		<content:encoded><![CDATA[<p>I think chained-methods are nice and useful, but they give the impression that the object is immutable &#8212; that it has to return a new instance rather than perform a mutation. The last thing you want is for clients not to realize they are mutating an object when they are. I would recommend using chained methods if and only if the object is immutable.</p>
<p>If there&#8217;s one exception, it&#8217;s StringBuffer, because (1) it&#8217;s used so frequently; (2) it so significantly reduces the amount of code; and (3) it&#8217;s very well known that it&#8217;s mutable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Desroches</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22462</link>
		<dc:creator>Roger Desroches</dc:creator>
		<pubDate>Thu, 14 Apr 2005 18:04:43 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22462</guid>
		<description>Just change it to

mockSubscriber.expects(once())
&#160;&amp;nbsp&#160;.method(&quot;receive&quot;).
&#160;&amp;nbsp&#160;.with( same(message) );

The line number of the exception will reflect the line call.  Also, the exception itself will reflect which method call; either expects, once() method, with, same, or the calling method.



I use &quot;chained calls&quot; all the time with string buffers.

StringBuffer buf = new StringBuffer();
buf.append(&quot;There have been &quot;)
&#160;&amp;nbsp&#160;.append(count)
&#160;&amp;nbsp&#160;.append(&quot; errors in the &quot;)
&#160;&amp;nbsp&#160;.append(systemName)
&#160;&amp;nbsp&#160;.append(&quot; system in the last &quot;)
&#160;&amp;nbsp&#160;.append(timeDelta).append(&quot; &quot;)
&#160;&amp;nbsp&#160;.append(timeGranularity);

</description>
		<content:encoded><![CDATA[<p>Just change it to</p>
<p>mockSubscriber.expects(once())<br />
&nbsp;&#038;nbsp&nbsp;.method(&#8221;receive&#8221;).<br />
&nbsp;&#038;nbsp&nbsp;.with( same(message) );</p>
<p>The line number of the exception will reflect the line call.  Also, the exception itself will reflect which method call; either expects, once() method, with, same, or the calling method.</p>
<p>I use &#8220;chained calls&#8221; all the time with string buffers.</p>
<p>StringBuffer buf = new StringBuffer();<br />
buf.append(&#8221;There have been &#8220;)<br />
&nbsp;&#038;nbsp&nbsp;.append(count)<br />
&nbsp;&#038;nbsp&nbsp;.append(&#8221; errors in the &#8220;)<br />
&nbsp;&#038;nbsp&nbsp;.append(systemName)<br />
&nbsp;&#038;nbsp&nbsp;.append(&#8221; system in the last &#8220;)<br />
&nbsp;&#038;nbsp&nbsp;.append(timeDelta).append(&#8221; &#8220;)<br />
&nbsp;&#038;nbsp&nbsp;.append(timeGranularity);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: icoloma</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22461</link>
		<dc:creator>icoloma</dc:creator>
		<pubDate>Wed, 13 Apr 2005 18:44:24 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22461</guid>
		<description>This is not a good thing. Get a NPE in this sentence and try to debug it.

Java is not english, don&#039;t try to make it so.

mockSubscriber.expects(once()).method(&quot;receive&quot;).with( same(message) );
</description>
		<content:encoded><![CDATA[<p>This is not a good thing. Get a NPE in this sentence and try to debug it.</p>
<p>Java is not english, don&#8217;t try to make it so.</p>
<p>mockSubscriber.expects(once()).method(&#8221;receive&#8221;).with( same(message) );</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Newman</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22460</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Wed, 13 Apr 2005 10:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22460</guid>
		<description>Can I suggest looking at the Law of demeter? It&#039;s been around a while: http://c2.com/cgi/wiki?LawOfDemeter

It&#039;s one of those OO things.

Using &quot;it&#039;s in the Java API!&quot; as justification for something has left us with a large amount of code that&#039;s as nice to use as the calendar API. The JMock  example is something else entirely - there it&#039;s using the syntax of Java to produce readable assertions - it&#039;s an allowable exception (in my opinion) to the law of demeter.
</description>
		<content:encoded><![CDATA[<p>Can I suggest looking at the Law of demeter? It&#8217;s been around a while: <a href="http://c2.com/cgi/wiki?LawOfDemeter" rel="nofollow">http://c2.com/cgi/wiki?LawOfDemeter</a></p>
<p>It&#8217;s one of those OO things.</p>
<p>Using &#8220;it&#8217;s in the Java API!&#8221; as justification for something has left us with a large amount of code that&#8217;s as nice to use as the calendar API. The JMock  example is something else entirely &#8211; there it&#8217;s using the syntax of Java to produce readable assertions &#8211; it&#8217;s an allowable exception (in my opinion) to the law of demeter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Flanagan</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22459</link>
		<dc:creator>David Flanagan</dc:creator>
		<pubDate>Wed, 13 Apr 2005 08:23:44 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22459</guid>
		<description>java.nio has chained methods.

In the right API, and used in moderation, they can be cool.  But Keith is right that they can easily be abused and lead to ugly, confusing code.
</description>
		<content:encoded><![CDATA[<p>java.nio has chained methods.</p>
<p>In the right API, and used in moderation, they can be cool.  But Keith is right that they can easily be abused and lead to ugly, confusing code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cameron</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22458</link>
		<dc:creator>Cameron</dc:creator>
		<pubDate>Wed, 13 Apr 2005 05:16:42 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22458</guid>
		<description>That Keith dude is right on. Your complaint is with the language, not with the return value declaration! What you really are asking for is a &quot;with&quot; clause. Peace.
</description>
		<content:encoded><![CDATA[<p>That Keith dude is right on. Your complaint is with the language, not with the return value declaration! What you really are asking for is a &#8220;with&#8221; clause. Peace.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Lea</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22457</link>
		<dc:creator>Keith Lea</dc:creator>
		<pubDate>Tue, 12 Apr 2005 22:42:51 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22457</guid>
		<description>I think that chained method calls are ugly, confusing, and that they pollute the simplicity of Java.
</description>
		<content:encoded><![CDATA[<p>I think that chained method calls are ugly, confusing, and that they pollute the simplicity of Java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross Judson</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22456</link>
		<dc:creator>Ross Judson</dc:creator>
		<pubDate>Tue, 12 Apr 2005 21:00:18 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22456</guid>
		<description>Let this be a lesson to you, young man.  Do not attempt to put type annotations into comment examples ;)

</description>
		<content:encoded><![CDATA[<p>Let this be a lesson to you, young man.  Do not attempt to put type annotations into comment examples ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross Judson</title>
		<link>http://almaer.com/blog/caller-context-and-listaddaddadd/comment-page-1#comment-22455</link>
		<dc:creator>Ross Judson</dc:creator>
		<pubDate>Tue, 12 Apr 2005 20:59:08 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/caller-context-and-listaddaddadd#comment-22455</guid>
		<description>I&#039;ve been working on a JDK 5 library that lets you do something like what you&#039;re talking about.  I started with the notion that Iterable was a good thing, but Stream extends Iterable could be much better.  Note that as calls are made in these examples the full type of the stream is preserved...if you create a subclass of the stream types you still get to call your subclass&#039;s methods.

Hopefully it&#039;ll get to the point where I can put it out somewhere.  Right now I use it to do lots of different things; SQL-like data selection, reflection over object graphs, etc...

A couple of call examples follow.

public void testPipeline() {
Pipeline pipeStart = new Pipeline();

Stream&gt; is = pipeStart
.shuffle()
.first(5)
.sort()
.transform(new Transform(){
public String transform(Integer from)
{
return &quot;Hello &quot; + from;
}})
.end(pipeStart);

is = is.insert(Integers.random(25));
is.dump(&quot;Hello &quot;);

System.out.println(is.getClass().getName());

//.dump(&quot;Hello&quot;);


}

public void testAugment2() {
randomEmployees(100)
.where(new Transform() {
public Boolean transform(Employee from) {
return from.getName().startsWith(&quot;Kurt&quot;);
}})
.dump(&quot;Employees starting with Kurt&quot;)
.transform(new Transform&gt;() {
public Tuple2 transform(Employee from) {
return Tuple.make(from, from.hashCode());
} })
.dump(&quot;Employee--hashcode tuples&quot;);
}
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been working on a JDK 5 library that lets you do something like what you&#8217;re talking about.  I started with the notion that Iterable was a good thing, but Stream extends Iterable could be much better.  Note that as calls are made in these examples the full type of the stream is preserved&#8230;if you create a subclass of the stream types you still get to call your subclass&#8217;s methods.</p>
<p>Hopefully it&#8217;ll get to the point where I can put it out somewhere.  Right now I use it to do lots of different things; SQL-like data selection, reflection over object graphs, etc&#8230;</p>
<p>A couple of call examples follow.</p>
<p>public void testPipeline() {<br />
Pipeline pipeStart = new Pipeline();</p>
<p>Stream> is = pipeStart<br />
.shuffle()<br />
.first(5)<br />
.sort()<br />
.transform(new Transform(){<br />
public String transform(Integer from)<br />
{<br />
return &#8220;Hello &#8221; + from;<br />
}})<br />
.end(pipeStart);</p>
<p>is = is.insert(Integers.random(25));<br />
is.dump(&#8221;Hello &#8220;);</p>
<p>System.out.println(is.getClass().getName());</p>
<p>//.dump(&#8221;Hello&#8221;);</p>
<p>}</p>
<p>public void testAugment2() {<br />
randomEmployees(100)<br />
.where(new Transform() {<br />
public Boolean transform(Employee from) {<br />
return from.getName().startsWith(&#8221;Kurt&#8221;);<br />
}})<br />
.dump(&#8221;Employees starting with Kurt&#8221;)<br />
.transform(new Transform>() {<br />
public Tuple2 transform(Employee from) {<br />
return Tuple.make(from, from.hashCode());<br />
} })<br />
.dump(&#8221;Employee&#8211;hashcode tuples&#8221;);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
