<?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: To Closure Or Not To Closure</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Barney</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-417</link>
		<dc:creator>Barney</dc:creator>
		<pubDate>Wed, 11 Oct 2006 15:04:02 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-417</guid>
		<description>Spike,

A callback is not a closure.  Callbacks don&#039;t carry the scope they&#039;re defined in, so the callback mechanism you propose would correctly resolve external variable dependancies if the variable scope that the callback is defined in is the same as the variable scope the trasact() function executes in.  Chances are slim that&#039;ll be the case.  With a closure, the callback&#039;s variable scope would come along for free, so you don&#039;t have the issues.

Sean hit the nail right on the head.  A callback is only 20% of what a closure is, and without the full closure capability, the callback mechanism would only suffice for very simplistic operations (ones with no external variable dependancies).
</description>
		<content:encoded><![CDATA[<p>Spike,</p>
<p>A callback is not a closure.  Callbacks don't carry the scope they're defined in, so the callback mechanism you propose would correctly resolve external variable dependancies if the variable scope that the callback is defined in is the same as the variable scope the trasact() function executes in.  Chances are slim that'll be the case.  With a closure, the callback's variable scope would come along for free, so you don't have the issues.</p>
<p>Sean hit the nail right on the head.  A callback is only 20% of what a closure is, and without the full closure capability, the callback mechanism would only suffice for very simplistic operations (ones with no external variable dependancies).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barney</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-416</link>
		<dc:creator>Barney</dc:creator>
		<pubDate>Wed, 11 Oct 2006 14:52:38 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-416</guid>
		<description>Bruce, 

Good catch on the Java anonymous inner classes.  You are absolute correct; only local variable (including method parameters) need to be marked as final.  The reason for this is apparent with a little thought: those variables only last for the duration of the method invocation, while the outer class&#039;s instance variables persist until the instance dies.  So the instance variables are inherently &quot;final enough&quot;.  I will ammend the entry to that effect.</description>
		<content:encoded><![CDATA[<p>Bruce, </p>
<p>Good catch on the Java anonymous inner classes.  You are absolute correct; only local variable (including method parameters) need to be marked as final.  The reason for this is apparent with a little thought: those variables only last for the duration of the method invocation, while the outer class's instance variables persist until the instance dies.  So the instance variables are inherently "final enough".  I will ammend the entry to that effect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-415</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Wed, 11 Oct 2006 01:54:42 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-415</guid>
		<description>Oh I give up... my code fragments just aren&#039;t going to show... I hope folks can see what I&#039;m trying to suggest...</description>
		<content:encoded><![CDATA[<p>Oh I give up&#8230; my code fragments just aren't going to show&#8230; I hope folks can see what I'm trying to suggest&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-414</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Tue, 10 Oct 2006 23:12:38 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-414</guid>
		<description>I think Barney&#039;s point was that what you really want is for the query to be able to bind to local variables:

[cfset var userId = arguments.event.getValue(&quot;id&quot;)&gt;

[cfset variables.transactionManager.doInTransaction(
  cf.new(&quot; [cfqueryparam ... #userId# ..&gt; [/cfquery&gt; [cfreturn theQuery&gt;&quot;).bind(userId=userId)
)&gt;

And this will bind the local userId variable into the query but still execute inside the transaction. The cf variable is a ClosureFactory instance and doInTransaction() would need to do callback.call() instead of just callback().</description>
		<content:encoded><![CDATA[<p>I think Barney's point was that what you really want is for the query to be able to bind to local variables:</p>
<p>[cfset var userId = arguments.event.getValue("id")&gt;</p>
<p>[cfset variables.transactionManager.doInTransaction(<br />
  cf.new(" [cfqueryparam &#8230; #userId# ..&gt; [/cfquery&gt; [cfreturn theQuery&gt;").bind(userId=userId)<br />
)&gt;</p>
<p>And this will bind the local userId variable into the query but still execute inside the transaction. The cf variable is a ClosureFactory instance and doInTransaction() would need to do callback.call() instead of just callback().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-413</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Tue, 10 Oct 2006 23:11:57 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-413</guid>
		<description>I think Barney&#039;s point was that what you really want is for the query to be able to bind to local variables:



   &quot;).bind(userId=userId)
)&gt;

And this will bind the local userId variable into the query but still execute inside the transaction. The cf variable is a ClosureFactory instance and doInTransaction() would need to do callback.call() instead of just callback().</description>
		<content:encoded><![CDATA[<p>I think Barney's point was that what you really want is for the query to be able to bind to local variables:</p>
<p>   ").bind(userId=userId)<br />
)&gt;</p>
<p>And this will bind the local userId variable into the query but still execute inside the transaction. The cf variable is a ClosureFactory instance and doInTransaction() would need to do callback.call() instead of just callback().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spike</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-412</link>
		<dc:creator>Spike</dc:creator>
		<pubDate>Tue, 10 Oct 2006 18:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-412</guid>
		<description>Hi Barney,
You can use callbacks just fine in ColdFusion.

The code below outputs the content of the query exactly as you would want it to (assuming the code shows up in the comments of course.).

Obviously you&#039;d want to replace the opening and closing cftransaction tags with your transactionManager.enterTransactionalBlock() and transactionManager.exitTransactionalBlock() calls, but apart from that it should work fine.

&lt;cffunction name=&quot;getPages&quot;&gt;
  &lt;cfset var q  = &quot;&quot; /&gt;
  &lt;cfquery datasource=&quot;mySite&quot; name=&quot;q&quot;&gt;
    SELECT *
    FROM pages
  &lt;/cfquery&gt;
  &lt;cfreturn q /&gt;
&lt;/cffunction&gt;

&lt;cffunction name=&quot;transact&quot;&gt;
  &lt;cfargument name=&quot;queryMethod&quot; /&gt;
  &lt;cfset var result = &quot;&quot; /&gt;
  &lt;cftransaction&gt;
    &lt;cfset result = queryMethod() /&gt;
  &lt;/cftransaction&gt;
  &lt;cfreturn result /&gt;
&lt;/cffunction&gt;

&lt;cfset result = transact(getPages) /&gt;
&lt;cfdump var=&quot;#result#&quot; /&gt;</description>
		<content:encoded><![CDATA[<p>Hi Barney,<br />
You can use callbacks just fine in ColdFusion.</p>
<p>The code below outputs the content of the query exactly as you would want it to (assuming the code shows up in the comments of course.).</p>
<p>Obviously you'd want to replace the opening and closing cftransaction tags with your transactionManager.enterTransactionalBlock() and transactionManager.exitTransactionalBlock() calls, but apart from that it should work fine.</p>
<p>&lt;cffunction name="getPages"&gt;<br />
  &lt;cfset var q  = "" /&gt;<br />
  &lt;cfquery datasource="mySite" name="q"&gt;<br />
    SELECT *<br />
    FROM pages<br />
  &lt;/cfquery&gt;<br />
  &lt;cfreturn q /&gt;<br />
&lt;/cffunction&gt;</p>
<p>&lt;cffunction name="transact"&gt;<br />
  &lt;cfargument name="queryMethod" /&gt;<br />
  &lt;cfset var result = "" /&gt;<br />
  &lt;cftransaction&gt;<br />
    &lt;cfset result = queryMethod() /&gt;<br />
  &lt;/cftransaction&gt;<br />
  &lt;cfreturn result /&gt;<br />
&lt;/cffunction&gt;</p>
<p>&lt;cfset result = transact(getPages) /&gt;<br />
&lt;cfdump var="#result#" /&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruce</title>
		<link>https://www.barneyb.com/barneyblog/2006/10/09/to-closure-or-not-to-closure/comment-page-1/#comment-411</link>
		<dc:creator>Bruce</dc:creator>
		<pubDate>Tue, 10 Oct 2006 10:06:59 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=184#comment-411</guid>
		<description>Thanks for posting this.  I read Sean&#039;s post on Closures and I was like WTF.  Now I see their benefit.  As a CF and Java developer I wasn&#039;t familar with the concept, though as you explain so well Java has a closure type feature.

Concerning your last paragraph about Java&#039;s anonymous inner classes--I believe that only local variables must be marked as final, instance fields can be referenced by the anonymous inner class and don&#039;t have to be marked as final.

See: http://www.developer.com/java/other/article.php/3300881</description>
		<content:encoded><![CDATA[<p>Thanks for posting this.  I read Sean's post on Closures and I was like WTF.  Now I see their benefit.  As a CF and Java developer I wasn't familar with the concept, though as you explain so well Java has a closure type feature.</p>
<p>Concerning your last paragraph about Java's anonymous inner classes&#8211;I believe that only local variables must be marked as final, instance fields can be referenced by the anonymous inner class and don't have to be marked as final.</p>
<p>See: <a href="http://www.developer.com/java/other/article.php/3300881" rel="nofollow">http://www.developer.com/java/other/article.php/3300881</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
