<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>porges &#187; Broken</title>
	<atom:link href="http://porg.es/blog/tag/broken/feed" rel="self" type="application/rss+xml" />
	<link>http://porg.es/blog</link>
	<description></description>
	<lastBuildDate>Thu, 12 Jan 2012 23:45:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Unicode as she is broke</title>
		<link>http://porg.es/blog/unicode-as-she-is-broke</link>
		<comments>http://porg.es/blog/unicode-as-she-is-broke#comments</comments>
		<pubDate>Mon, 14 Mar 2011 08:34:02 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Broken]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=418</guid>
		<description><![CDATA[Do you think your string-handling code is robust? Are there any problems with the following snippets? // Write the first character: Console.WriteLine&#40;s&#91;0&#93;&#41;; &#160; // Reverse the string: var backwards = s.ToArray&#40;&#41;; Array.Reverse&#40;backwards&#41;; Console.WriteLine&#40;new string&#40;backwards&#41;&#41;; &#160; // List the characters, separated by commas: Console.WriteLine&#40;string.Join&#40;&#34;, &#34;, s.ToArray&#40;&#41;&#41;&#41;; All of these are potential bugs. Just set the following [...]]]></description>
			<content:encoded><![CDATA[<p>Do you think your string-handling code is robust? Are there any problems with the following snippets?</p>
<p><span id="more-418"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Write the first character:</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>s<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Reverse the string:</span>
var backwards <span style="color: #008000;">=</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Reverse</span><span style="color: #008000;">&#40;</span>backwards<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#40;</span>backwards<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// List the characters, separated by commas:</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Join</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;, &quot;</span>, s<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

 <a class="simple-footnote" title="Note that even if you have a UTF-16 implementation with a &#8220;non-broken&#8221; char, the reversal given here isn&#8217;t valid. For one thing, it will put combining characters in the wrong place. The reversal of a string is also potentially locale-dependent: one can argue that the reversal of &#8220;Dijkstra&#8221; (Dutch) should be &#8220;artsijkD&#8221;." id="return-note-418-1" href="#note-418-1"><sup>1</sup></a>
<p>All of these are potential bugs.</p>
<p>Just set the following and you&#8217;ll get some nice output:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> s <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;𠂔&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<pre>�
��
�,�</pre>
<p>There are other problems as well:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> A <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;𝔄&quot;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// MATHEMATICAL FRAKTUR CAPITAL A, if you can't see it</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsUpper</span><span style="color: #008000;">&#40;</span>A<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// False</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsUpper</span><span style="color: #008000;">&#40;</span>A<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// False</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsUpper</span><span style="color: #008000;">&#40;</span>A,<span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// True - this is the correct way</span></pre></div></div>

<p>Why is this?</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetUnicodeCategory</span><span style="color: #008000;">&#40;</span>A<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Surrogate</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetUnicodeCategory</span><span style="color: #008000;">&#40;</span>A<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Surrogate</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetUnicodeCategory</span><span style="color: #008000;">&#40;</span>A,<span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// UppercaseLetter</span></pre></div></div>

<p>Ah.</p>
<h2>The UCS-2 Hangover</h2>
<p>These are all symptoms of &#8216;migrated&#8217; libraries, originally developed for UCS-2 (in the early days of Unicode), and now touted as UTF-16.</p>
<p>Whereas UCS-2 was a fixed-width, 16-bit format, UTF-16 is a variable-width format which uses pairs of &#8216;surrogate&#8217; 16-bit units to support characters that UCS-2 does not. These are the characters outside the Basic Multilingual Plane (BMP), sometimes termed the &#8216;astral characters&#8217;.</p>
<p>Libraries with <code>char</code> as a 16-bit quantity are living a lie. They live in a delusional world of fixed-width characters, where they let you believe you can index, substring, and play around at will, whereas:</p>
<ul>
<li>You cannot select arbitrary substrings &mdash; you might get half a character included.</li>
<li>You cannot index into the string arbitrarily &mdash; you might select half a character.</li>
<li>You cannot treat a string as a bunch of isolated characters &mdash; the surrogate pairs will get broken up.</li>
</ul>
<h2>So?</h2>
<p>The general response seems to be &#8220;it doesn&#8217;t matter, most of the stuff I deal with is in the BMP, so I don&#8217;t care&#8221;.</p>
<p>A simple example of the problem with this: if any of these &#8216;orphan surrogates&#8217; gets into an XML document, you have an application-stopping bug on your hands. (Just ask <a href="http://www.linqpad.net/">LINQPad</a>, which refuses to run any of the examples in the first block of code. Luckily it has good exception handling.) <a href="http://www.google.co.nz/search?q=&quot;The+surrogate+pair+is+invalid&quot;">A quick Google search</a> shows that many developers are already encountering this problem.</p>
<p>All of the latest CJK extensions (B, C, D) also live in the <a href="http://en.wikipedia.org/wiki/Supplementary_Ideographic_Plane#Supplementary_Ideographic_Plane">Supplementary Ideographic Plane</a> (SIP, the second non-BMP plane). I haven&#8217;t really been able to find out just how many of these characters are actually used in any real sense, but you&#8217;re going to encounter them eventually (and <a href="http://www.unicode.org/charts/PDF/U1F600.pdf">recent additions to Unicode</a> might start turning up).</p>
<h3>There&#8217;s a hole in your abstraction</h3>
<p>The problem with UCS-2&ndash;flavoured UTF-16 is that it hands all the work of handling surrogate characters correctly over to the developer.</p>
<p>Underlining the third character in a string sounds like a simple task. But, if someone slips in a non-BMP character, then&#8230;</p>
 <a class="simple-footnote" title="Again, this won&#8217;t work perfectly even with a &#8220;non-broken&#8221; char type. Combining characters need to be considered. This argues for a more sophisticated library in general, one that has an idea of a visible &#8216;stack&#8217; of codepoints (or some other basic glyph construct). A discussion for another time&#8230;" id="return-note-418-2" href="#note-418-2"><sup>2</sup></a>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var s <span style="color: #0600FF; font-weight: bold;">in</span> <span style="color: #008000;">new</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span><span style="color: #666666;">&quot;0123456789&quot;</span>, <span style="color: #666666;">&quot;〇一二三四五六七八九&quot;</span>, <span style="color: #666666;">&quot;𝟘123456789&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>s<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>,<span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&lt;span style='border:2px #FF4500 solid'&gt;&quot;</span> <span style="color: #008000;">+</span> s<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&lt;/span&gt;&quot;</span> <span style="color: #008000;">+</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>
01<span style='border:2px #FF4500 solid'>2</span>3456789<br />
〇一<span style='border:2px #FF4500 solid'>二</span>三四五六七八九<br />
𝟘<span style='border:2px #FF4500 solid'>1</span>23456789
</p>
<p>&#8230;and now the developer has to write their own linear-time indexing functions to actually find the character they need. This is not a good abstraction.</p>
<h2>From here</h2>
<p>Once you give up the idea that you can safely treat UTF-16 as a fixed-width format, it really doesn&#8217;t have anything going for it. (Perhaps this is why the idea is so firmly embedded &mdash; elements of <a href="http://en.wikipedia.org/wiki/Cognitive_dissonance">cognitive dissonance</a>.)</p>
<p>Here&#8217;s a quick (mainly biased) diagram:</p>
<p><a href="http://porg.es/blog/wp-content/uploads/2010/11/unicode.png"><img src="http://porg.es/blog/wp-content/uploads/2010/11/unicode.png" alt="" title="Comparison of UTFs" width="546" height="300" class="aligncenter size-full wp-image-460" /></a></p>
<div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-418-1">Note that even if you have a UTF-16 implementation with a &#8220;non-broken&#8221; <code>char</code>, the reversal given here isn&#8217;t valid. For one thing, it will put combining characters in the wrong place. The reversal of a string is also potentially locale-dependent: one can argue that the reversal of &#8220;Dijkstra&#8221; (Dutch) should be &#8220;artsijkD&#8221;. <a href="#return-note-418-1">&#8617;</a></li><li id="note-418-2">Again, this won&#8217;t work perfectly even with a &#8220;non-broken&#8221; <code>char</code> type. Combining characters need to be considered. This argues for a more sophisticated library in general, one that has an idea of a visible &#8216;stack&#8217; of codepoints (or some other basic glyph construct). A discussion for another time&#8230; <a href="#return-note-418-2">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/unicode-as-she-is-broke/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NullPointerException</title>
		<link>http://porg.es/blog/nullpointerexception</link>
		<comments>http://porg.es/blog/nullpointerexception#comments</comments>
		<pubDate>Thu, 24 May 2007 21:26:41 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[Broken]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Critique]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Thought]]></category>
		<category><![CDATA[Types]]></category>

		<guid isPermaLink="false">http://porg.es/blog/nullpointerexception</guid>
		<description><![CDATA[Why is this such an insidious error in Java? (An opinion piece!) A Comparison Firstly, I&#8217;ll show a short comparison between some Java code and some code from a language that doesn&#8217;t have NullPointerExceptions, but does have something that allows you to accomplish anything you might want to do with null pointers. This Java code: [...]]]></description>
			<content:encoded><![CDATA[<p>Why is this such an insidious error in Java? (An opinion piece!)</p>
<h3>A Comparison</h3>
<p>Firstly, I&#8217;ll show a short comparison between some Java code and some code from a language that doesn&#8217;t have <code>NullPointerException</code>s, but does have something that allows you to accomplish anything you might want to do with null pointers.</p>
<p>This Java code:</p>
<pre><code>AnObject thing = someMethod();</code></pre>
<p>is equivalent to the following Haskell:</p>
<pre><code>let thing = Maybe AnObject</code></pre>
<p>That is, every Java object reference is possibly null. What this means is that (using the type notation mentioned in earlier posts) every Java reference has the type:</p>
<p><img src='/blog/wp-content/plugins/latexrender/pictures/80c7aa7402953bdabc5fcf23a7a9b406.gif' title='ObjectReference[Object] = 1 + Object' alt='ObjectReference[Object] = 1 + Object' align=absmiddle></p>
<p><small>(Every object reference for an object is either to &#8216;null&#8217; (<abbr title="also known as">AKA</abbr> &#8216;unit&#8217; or &#8216;singleton&#8217<img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_wink.gif" alt="" />, or the object itself.)</small></p>
<p>&#8230; and when you&#8217;re dealing with so many objects—Java is, after all, an object-oriented language, so (almost) everything is an object—this simple little &#8220;+1&#8243; gets lost easily.</p>
<h3>Why so bad?</h3>
<p>This wouldn&#8217;t seem to be such a big deal, but when contrasted against Java&#8217;s penchant for making things (sometimes painfully) explicit—think <code>public static void main (string argh!)</code>—a small, implicit item like this is easily overlooked. Conversely, one might say that the verbosity of Java <em>increases</em> the cognitive load of understanding its code; thus helping the chances of a small mistake like this sneaking through.</p>
<p>Either way, I think I can say that this is objectively A Bad Thing. C# has gone some of the way to a &#8216;correct&#8217; solution in its introduction of possibly-null primitives, which are explicitly marked with a <code>?</code> (such as <code>int?</code>), but unfortunately this hasn&#8217;t been &#8216;back-ported&#8217; to the rest of the language. If one were able to force between possibly-null and definitely-not-null references in C#—perhaps by the analogous <code>object?</code> vs. <code>object</code>, this would help to reduce the number of errors &#8216;hidden&#8217; by the syntax.</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/nullpointerexception/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to say nothing</title>
		<link>http://porg.es/blog/how-to-say-nothing</link>
		<comments>http://porg.es/blog/how-to-say-nothing#comments</comments>
		<pubDate>Sat, 14 Apr 2007 23:36:34 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[Broken]]></category>
		<category><![CDATA[Critique]]></category>
		<category><![CDATA[Enterprisey]]></category>

		<guid isPermaLink="false">http://porg.es/blog/how-to-say-nothing</guid>
		<description><![CDATA[Has no one told the people behind the Workflow Management Coalition that April Fool&#8217;s passed over two weeks ago? Intrigued at what I first thought was a joke, I downloaded one of the proudly-presented documents on the front page: Understanding the BPMN-XPDL-BPEL value chain. I chose it because of the three as-yet-unknown acronyms in the [...]]]></description>
			<content:encoded><![CDATA[<p>Has no one told the people behind the <a href="http://www.wfmc.org">Workflow Management Coalition</a> that April Fool&#8217;s passed over two weeks ago?</p>
<p>Intrigued at what I first thought was a joke, I downloaded one of the proudly-presented documents on the front page: <a href="http://www.wfmc.org/documents/palmer.BIJ.nov-dec06.pdf"><i>Understanding the BPMN-XPDL-BPEL value chain</i></a>. I chose it because of the three as-yet-unknown acronyms in the title&#8230; and I wasn&#8217;t disappointed.</p>
<p><span id="more-98"></span></p>
<p>I present you with the following gem, lifted from one paragraph of the article:</p>
<blockquote><p>Several BPM engines are able to run XPDL natively, which allows run-time modification and process migration to be readily supported. Where these processes focus on broader-scope collaboration among people, they can remain within XPDL/BPMN. Where pieces are decomposed into system-to-system interactions, these can be translated to BPEL for transmission to an EAI-oriented BPM engine. These are three very different and very compatible roles. But that’s the nature of the value chain—BPEL and XPDL are entirely different things for entirely different purposes.</p></blockquote>
<p>I suppose the warning sign should have been their slogan:</p>
<blockquote><p>Process Thought Leadership™</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/how-to-say-nothing/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy, persistent, local DNS cache to reduce lookup times</title>
		<link>http://porg.es/blog/easy-persistent-local-dns-cache-to-reduce-lookup-times-2</link>
		<comments>http://porg.es/blog/easy-persistent-local-dns-cache-to-reduce-lookup-times-2#comments</comments>
		<pubDate>Thu, 05 Oct 2006 02:26:15 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[Broken]]></category>
		<category><![CDATA[Cool]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://porg.es/blog/easy-persistent-local-dns-cache-to-reduce-lookup-times-2</guid>
		<description><![CDATA[Important Update! Don&#8217;t use this method any more! I have a much easier way to do it in a more recent post. But for posterity&#8230; First install resolvconf and pdnsd: sudo apt-get install pdnsd resolvconf. Resolvconf handles the messy interaction between different programs fighting over the /etc/resolv.conf file, and pdnsd provides a persistent DNS daemon, [...]]]></description>
			<content:encoded><![CDATA[<h3>Important Update!</h3>
<p>Don&#8217;t use this method any more! I have a much easier way to do it in a <a href="http://porg.es/blog/easier-local-dns-cache">more recent post</a>.</p>
<h3>But for posterity&#8230;</h3>
<p>First install resolvconf and pdnsd: <code>sudo apt-get install pdnsd resolvconf</code>. Resolvconf handles the messy interaction between different programs fighting over the <code>/etc/resolv.conf</code> file, and pdnsd provides a <b>p</b>ersistent <b>DNS</b> <b>d</b>aemon, which will cache the DNS lookups on your machine in order to make browsing faster.</p>
<p>Next, you just need to edit pdnsd&#8217;s configuration file, <code>/etc/pdnsd.conf</code> as root. Edit it to look like this:</p>
<pre><code>global {
        perm_cache=512;
        cache_dir="/var/cache/pdnsd";
        max_ttl=604800;
        run_as="pdnsd";
        paranoid=on;
#       next setting allows ppp/ip-up update the name servers -- ABa / 20040213
        status_ctl=on;
        server_port=53;
        server_ip="127.0.0.1";
}

#Edit these to be your own servers if wished:
server {
        label = "OpenDNS";
        ip=208.67.222.222,208.67.220.220;
        proxy_only=on;
        timeout=10;
}

# if you installed resolvconf, and status_ctl=on
server {
    label="resolvconf";
}

source {
        ttl=86400;
        owner="localhost.";
#       serve_aliases=on;
        file="/etc/hosts";
}</pre>
<p></code></p>
<p>And finally, restart pdnsd with <code>sudo /etc/init.d/pdnsd restart</code> to use the new settings. In the example above, I've used OpenDNS's servers, but you can change these to whatever you want. As far as actual results go:</p>
<blockquote><p><code>~$ dig example.com</p>
<p>; <<>> DiG 9.3.2 <<>> example.com<br />
;; global options:  printcmd<br />
;; Got answer:<br />
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17447<br />
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0</p>
<p>;; QUESTION SECTION:<br />
;example.com.                   IN      A</p>
<p>;; ANSWER SECTION:<br />
example.com.            172800  IN      A       192.0.34.166</p>
<p><b>;; Query time: 513 msec</b><br />
;; SERVER: 127.0.0.1#53(127.0.0.1)<br />
;; WHEN: Thu Oct  5 15:24:19 2006<br />
;; MSG SIZE  rcvd: 45</p>
<p>$ dig example.com</p>
<p>; <<>> DiG 9.3.2 <<>> example.com<br />
;; global options:  printcmd<br />
;; Got answer:<br />
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19338<br />
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0</p>
<p>;; QUESTION SECTION:<br />
;example.com.                   IN      A</p>
<p>;; ANSWER SECTION:<br />
example.com.            172799  IN      A       192.0.34.166</p>
<p><b>;; Query time: 0 msec</b><br />
;; SERVER: 127.0.0.1#53(127.0.0.1)<br />
;; WHEN: Thu Oct  5 15:24:20 2006<br />
;; MSG SIZE  rcvd: 45<br />
</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/easy-persistent-local-dns-cache-to-reduce-lookup-times-2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unicode breaks Google search</title>
		<link>http://porg.es/blog/unicode-breaks-google-search</link>
		<comments>http://porg.es/blog/unicode-breaks-google-search#comments</comments>
		<pubDate>Mon, 26 Jun 2006 02:08:19 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[Broken]]></category>
		<category><![CDATA[Critique]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://porg.es/blog/unicode-breaks-google-search</guid>
		<description><![CDATA[A search for the phrase &#34;It’s like a light of a new day,&#34; breaks in more than one way. Not only does Google search fail to recognize that &#8220;it&#8217;s&#8221; is a word, it also ignores the quote marks, searching for the phrase as individual words.]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://www.google.com/search?q=%22It%E2%80%99s+like+a+light+of+a+new+day%2C%22&#038;start=0&#038;ie=utf-8&#038;oe=utf-8&#038;client=firefox&#038;rls=org.mozilla:en-US:unofficial">search for the phrase &quot;It’s like a light of a new day,&quot;</a> breaks in more than one way.</p>
<p>Not only does Google search fail to recognize that &#8220;it&#8217;s&#8221; is a word, it also ignores the quote marks, searching for the phrase as individual words.</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/unicode-breaks-google-search/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

