<?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: The Open-Closure-Close Idiom in D</title>
	<atom:link href="http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/</link>
	<description>Hans-Eric Grönlund on software development</description>
	<pubDate>Thu, 16 Oct 2008 04:26:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Alexander Panek</title>
		<link>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3682</link>
		<dc:creator>Alexander Panek</dc:creator>
		<pubDate>Sat, 16 Feb 2008 10:56:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3682</guid>
		<description>On the other hand, it's easier to get an ol' dog to sit, when you provide a warm, cozy pillow under his bottom. Think of scope as your warm, cozy pillow. ;)</description>
		<content:encoded><![CDATA[<p>On the other hand, it&#8217;s easier to get an ol&#8217; dog to sit, when you provide a warm, cozy pillow under his bottom. Think of scope as your warm, cozy pillow. <img src='http://www.hans-eric.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans-Eric</title>
		<link>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3627</link>
		<dc:creator>Hans-Eric</dc:creator>
		<pubDate>Fri, 15 Feb 2008 11:40:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3627</guid>
		<description>I'm bound to agree. That is a nicer looking implementation.</description>
		<content:encoded><![CDATA[<p>I&#8217;m bound to agree. That is a nicer looking implementation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans-Eric</title>
		<link>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3626</link>
		<dc:creator>Hans-Eric</dc:creator>
		<pubDate>Fri, 15 Feb 2008 11:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3626</guid>
		<description>Indeed, scope is a great feature. For some reason I seem to be reluctant to use it. I'm sure that's just because, as we say in Sweden, "it's difficult to learn old dogs to sit."</description>
		<content:encoded><![CDATA[<p>Indeed, scope is a great feature. For some reason I seem to be reluctant to use it. I&#8217;m sure that&#8217;s just because, as we say in Sweden, &#8220;it&#8217;s difficult to learn old dogs to sit.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Panek</title>
		<link>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3556</link>
		<dc:creator>Alexander Panek</dc:creator>
		<pubDate>Thu, 14 Feb 2008 10:38:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3556</guid>
		<description>I think this looks way neater without try {} finally {}, but rather the oh-so-bad "new" syntax scope(exit):

&lt;code&gt;
Stream open(char[] fn, FileMode fm = FileMode.In,
            void delegate(Stream) closure = null)
{
	Stream f = new File(fn, fm);

	if (closure !is null) { 
		scope(exit) f.close;
		return closure(f);
	} else return f;
}

// Example usage
r"C:\log.txt".open(FileMode.Out, (Stream f) {
	OutputStream os = f;
	os.writefln("Log this");
});
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I think this looks way neater without try {} finally {}, but rather the oh-so-bad &#8220;new&#8221; syntax scope(exit):</p>
<p><code><br />
Stream open(char[] fn, FileMode fm = FileMode.In,<br />
            void delegate(Stream) closure = null)<br />
{<br />
	Stream f = new File(fn, fm);</p>
<p>	if (closure !is null) {<br />
		scope(exit) f.close;<br />
		return closure(f);<br />
	} else return f;<br />
}</p>
<p>// Example usage<br />
r&#8221;C:\log.txt&#8221;.open(FileMode.Out, (Stream f) {<br />
	OutputStream os = f;<br />
	os.writefln(&#8221;Log this&#8221;);<br />
});<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Wilson</title>
		<link>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3555</link>
		<dc:creator>David Wilson</dc:creator>
		<pubDate>Thu, 14 Feb 2008 10:27:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comment-3555</guid>
		<description>The D language has a "scope" keyword, as mentioned in the documentation. Basicall instead of all that jazz from the article, simply:


void doSomething()
{
    scope f = new File("/log.txt', ...);

    /* do work */
}


void main()
{
    doSomething();
    /* f is guaranteed by specification not to exist by
       this point, regardless of exceptions. */
}</description>
		<content:encoded><![CDATA[<p>The D language has a &#8220;scope&#8221; keyword, as mentioned in the documentation. Basicall instead of all that jazz from the article, simply:</p>
<p>void doSomething()<br />
{<br />
    scope f = new File(&#8221;/log.txt&#8217;, &#8230;);</p>
<p>    /* do work */<br />
}</p>
<p>void main()<br />
{<br />
    doSomething();<br />
    /* f is guaranteed by specification not to exist by<br />
       this point, regardless of exceptions. */<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.251 seconds -->
