<?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>(b)logophile</title>
	<atom:link href="http://www.logophile.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logophile.org/blog</link>
	<description>blog of a logophile (not "logos", but "λόγος")</description>
	<lastBuildDate>Sun, 13 May 2012 11:59:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Three books you probably haven&#8217;t heard of</title>
		<link>http://www.logophile.org/blog/2012/05/13/three-books-you-probably-havent-heard-of/</link>
		<comments>http://www.logophile.org/blog/2012/05/13/three-books-you-probably-havent-heard-of/#comments</comments>
		<pubDate>Sun, 13 May 2012 08:29:26 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[hipster]]></category>
		<category><![CDATA[recommendations]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1333</guid>
		<description><![CDATA[Since nothing earth-shaking has happened in Real Life&#174; lately, I thought I would recommend some books. But this isn&#8217;t a &#8220;best of my bookshelf&#8221; post: the best books I own you probably already know about. Instead these are the obscure but interesting ones: not necessarily recommended for everyone, but if one does catch your interest [...]]]></description>
			<content:encoded><![CDATA[<p>Since nothing earth-shaking has happened in Real Life&reg; lately, I thought I would recommend some books. But this isn&#8217;t a &#8220;best of my bookshelf&#8221; post: the best books I own you probably already know about. Instead these are the obscure but interesting ones: not necessarily recommended for everyone, but if one <em>does</em> catch your interest there&#8217;s a good chance you might not already have read it.</p>

<p><span id="more-1333"></span></p>

<h3><a href="http://www.librarything.com/work/22118"><em>On The Psychology of Military Incompetence</em></a> by Norman F. Dixon</h3>

<p>Analysing a number of historical military disasters to find a common psychological pattern. Dixon shows how the structure of military training and promotion systems encourages a particular set of character traits, which have a tendency to lead to disaster. From memory I don&#8217;t think he uses the term &#8220;cognitive dissonance,&#8221; but that&#8217;s a significant part of the story (the book is cited in <a href="http://www.librarything.com/work/2927391"><em>Mistakes Were Made (But Not By Me)</em></a>, which I also highly recommend). There are all sorts of bizarre anecdotes, that leave you wondering how these wackos were ever allowed to order other men into danger &#8212; like the commander who sent out a reconnaissance party then (presumably to avoid having to hear the bad news) moved his command post but didn&#8217;t tell anyone where he had moved it to.<sup>1</sup> Beyond these, though, the broad conclusions the author comes to are extremely relevant for anyone who wants (or doesn&#8217;t want but feels forced) to feel cynical about modern politics.</p>

<h3><a href="http://www.librarything.com/work/2927391"><em>Like a Fiery Elephant</em></a> by Jonathan Coe</h3>

<p>The biography of BS Johnson, and both man and biography are fascinating. Johnson was an avant garde novelist, playing all sorts of weird games with structure. (One novel consists of loose chapters kept in a box: the reader should read the first one first and the last one last, but may order the rest as she chooses. In another, each chapter repeats the same action from a different perspective, and position on the page exactly corresponds to the passage of time, so that in each chapter the top half of the third page describes the same event.) He was also a fairly messed-up and sometimes highly unpleasant character. He upheld honesty as the most important measure of artistic merit<sup>2</sup> but he lived in a world of constant self-deception. (The title comes from a student description which he liked to quote. Coe points out wryly that it&#8217;s very likely, given Johnson&#8217;s figure and poor classroom relations, that the child simply misspelled &#8220;fairy&#8221;, a possibility which Johnson apparently refused to contemplate.) He had ominous mystical experiences which never come into focus in the biography: he referred to them in his private writings but always, writing for himself, with the substance of the experience taken for granted. He committed suicide, and Coe successfully makes you feel both compassion for the pain that drove him to it and fury at the stubbornness with which he brought much of that pain upon himself.</p>

<p>Besides the subject matter, the amazing thing about this biography is how faithful it stays to the ideals of its subject. Coe writes about Johnson, but also about the process of trying to write in a way that Johnson would approve. He is explicit about his own emotional reaction to Johnson&#8217;s various foibles, and when he admits he can&#8217;t present an unbiased picture he gives instead extracts from letters, notes, interviews and so on, with little or no comment. It is honest in the broadest sense: true to the facts about this conflicted and often unpleasant person, but rich with empathy and compassion for him as well. It is also an extended exploration of what honesty can and cannot be in writing, and an attempt to test Johnson&#8217;s own principles by putting them into practise.</p>

<h2><a href="http://www.librarything.com/work/298985"><em>The Naming of Names</em></a> by Anna Pavord</h2>

<p>You might think that a book about the ancient and medieval names for plants would be boring. You would be wrong. Firstly, the cultural history is fascinating: how what we would think of as modern, scientific standards for describing plants (mainly for their medicinal properties) have gone in and out of fashion from Ancient Greece through the medieval Islamic world to the beginnings of the modern Western scientific revolution (she ends the book with Linnaeus, since the success of his systematic taxonomy takes all the interesting variation out of the story). But what really makes this book a keeper are the illustrations. Pavord has an extensive collection of plant manuscripts, often richly illustrated, and she has got reproduction rights for many more:<sup>3</sup> the book is packed with full-colour plates ranging from a hyper-realistic Dürer watercolour of an anonymous piece of turf to a stylised medieval mandrake complete with human-form root (although Pavord notes with approval that the artist has accurately rendered the structure of the flower heads and berries). There are so many illustrations, and many are so beautiful, that I would be tempted to buy a second copy to dismember, to frame the highlights and hang them on our wall. If that&#8217;s not a recommendation, I don&#8217;t know what is.</p>
<p>Notes:</p><ol class="footnotes"><li id="footnote_0_1333" class="footnote">No details or page references because I have misplaced the book, dammit. I think this one was during the Boer war.</li><li id="footnote_1_1333" class="footnote">Yes I&#8217;m oversimplifying enormously, but it does seem to have been his chief principle.</li><li id="footnote_2_1333" class="footnote">The text ends on page 402, and there are 158 plates: more double-page spreads have an illustration than don&#8217;t.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/05/13/three-books-you-probably-havent-heard-of/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Back from Greece</title>
		<link>http://www.logophile.org/blog/2012/05/06/back-from-greece/</link>
		<comments>http://www.logophile.org/blog/2012/05/06/back-from-greece/#comments</comments>
		<pubDate>Sun, 06 May 2012 17:56:19 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[glee]]></category>
		<category><![CDATA[gloating]]></category>
		<category><![CDATA[greece]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1319</guid>
		<description><![CDATA[So if you were thinking of robbing our house, wait for the next holiday. In Athens, a city with a population just slightly less than that of New Zealand, we managed to bump into someone we met last year on holiday. We played rebetiko with the members of Giouf and stayed in one apartment with [...]]]></description>
			<content:encoded><![CDATA[<p>So if you were thinking of robbing our house, wait for the next holiday.</p>

<p>In Athens, a city with a population just slightly less than that of New Zealand, we managed to bump into someone we met last year on holiday. We played rebetiko with the members of <a href="http://www.giouf.gr/">Giouf</a> and stayed in one apartment with a view of the Acropolis, and another with a pair of delightful kittens.</p>

<p>In Katerini, Olga&#8217;s mother fed me as implacably as always. We swam in the sea, three times. (Greeks seemed to think we were slightly mad, but the water, although not at summer temperatures, was perfectly pleasant to stay in for a half hour or so.)</p>

<p><a href="http://www.logophile.org/blog/wp-content/uploads/2012/05/wpid-2012-05-01-11.55.18.jpg"><img src="http://www.logophile.org/blog/wp-content/uploads/2012/05/wpid-2012-05-01-11.55.18-300x225.jpg" alt="" title="wpid-2012-05-01-11.55.18.jpg" width="300" height="225" class="aligncenter size-medium wp-image-1326" /></a></p>

<p>We drove to Thessaloniki to play rebetiko, and got home again at six in the morning.</p>

<p>For the first of May we joined some dear friends for a massive barbecue. To my great regret I failed to get a photograph of Stathis, four years old, with a wooden dagger in one hand and a souvlaki in the other, alternating between angelic stares at the goings on and enthusiastic gnawing on the souvlaki. I <em>did</em>, on the other hand, get a video of a beautiful oud performance by a friend-of-a-friend, but I managed to take it in portrait. Coming once I figure out how to turn it upright.</p>

<p><a href="http://www.logophile.org/blog/wp-content/uploads/2012/05/wpid-2012-05-01-15.28.19.jpg"><img src="http://www.logophile.org/blog/wp-content/uploads/2012/05/wpid-2012-05-01-15.28.19-300x225.jpg" alt="" title="wpid-2012-05-01-15.28.19.jpg" width="300" height="225" class="aligncenter size-medium wp-image-1323" /></a></p>

<p>We spent another night close to Thessaloniki, entertained by Karagiosi (shadow puppet theater) performed by an eight-year-old, and then by the same story in abbreviated form courtesy of his four-year-old brother. The day after we added another member to our family:</p>

<div id="attachment_1318" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.logophile.org/blog/wp-content/uploads/2012/05/wpid-2012-05-06-20.55.42.jpg"><img src="http://www.logophile.org/blog/wp-content/uploads/2012/05/wpid-2012-05-06-20.55.42-300x225.jpg" alt="" title="Jasmine the lavta" width="300" height="225" class="size-medium wp-image-1318" /></a><p class="wp-caption-text">Jasmine, or Γιασεμή, the lafta or lavta</p></div>

<p>Her name is Γιασεμή, or Jasmine (pronounced something like Ya-se-mi), from this <a href="http://www.youtube.com/watch?v=EkHxIa4ZeBs">beautiful song</a>. She is a lafta (or <a href="http://en.wikipedia.org/wiki/Lavta">lavta</a>), a Turkish instrument sometimes called the &#8220;politiko laouto&#8221; in Greece (&#8220;the lute of Istanbul&#8221;). My plan is to use her frets and simpler tuning system to learn to hear the intervals of makam theory (much more nuanced and beautiful than the simple semitones I grew up with), so that I can start playing them also on the (fretless) oud.</p>

<p>It seems like wherever we went I got job offers. Some of these were late-night wine-assisted affairs of the &#8220;I know some guys who do web programming from home, surely you can help them out?&#8221; kind, but there seem to be some real possibilities for the end of this year or beginning of 2013. Fingers most decidedly crossed on that count&#8230;</p>

<p>Finally we played one last rebetiko session with the Katerini crowd, and left (reluctantly) at two in the morning, just as the party was getting started, to drive to the airport for the flight home. Olga is now ensconced in front of the laptop watching the election results come in, and we&#8217;re already planning the summer holiday.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/05/06/back-from-greece/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silence is sexy</title>
		<link>http://www.logophile.org/blog/2012/04/26/silence-is-sexy/</link>
		<comments>http://www.logophile.org/blog/2012/04/26/silence-is-sexy/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 07:44:36 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blather]]></category>
		<category><![CDATA[haste]]></category>
		<category><![CDATA[pride]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1314</guid>
		<description><![CDATA[Work is busy, we played in a symphony last weekend, now we&#8217;re going to Greece for a week. Quiet times ahead for a wee while yet. In the meantime, if you&#8217;re not already reading Auch on Water, you should be. Also in the meantime, something we cooked up the other evening:]]></description>
			<content:encoded><![CDATA[<p>Work is busy, we played in a symphony last weekend, now we&#8217;re going to Greece for a week. Quiet times ahead for a wee while yet.</p>

<p>In the meantime, if you&#8217;re not already reading <a href="http://auchonwater.com/">Auch on Water</a>, you should be.</p>

<p>Also in the meantime, something we cooked up the other evening: <div id="attachment_1315" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.logophile.org/blog/wp-content/uploads/2012/04/2012-04-24-22.42.28.jpg"><img src="http://www.logophile.org/blog/wp-content/uploads/2012/04/2012-04-24-22.42.28-300x225.jpg" alt="" title="Our new business cards" width="300" height="225" class="size-medium wp-image-1315" /></a><p class="wp-caption-text">Our new business cards</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/04/26/silence-is-sexy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>’Ow’s yer ’elf?</title>
		<link>http://www.logophile.org/blog/2012/03/18/ows-yer-elf-4/</link>
		<comments>http://www.logophile.org/blog/2012/03/18/ows-yer-elf-4/#comments</comments>
		<pubDate>Sun, 18 Mar 2012 13:29:13 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ows-yer-elf]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1304</guid>
		<description><![CDATA[Today my public-shaming strategy paid off once again: I did a nice sweaty round of sun salutations rather than have to post here that my weekly exercise total was absolutely nothing. (In other words: yoga, once.) Not to worry though: the new rowing block starts tomorrow. The extremely observant may also notice a dearth of [...]]]></description>
			<content:encoded><![CDATA[<p>Today my public-shaming strategy paid off once again: I did a nice sweaty round of sun salutations rather than have to post here that my weekly exercise total was absolutely nothing. (In other words: yoga, once.) Not to worry though: the new rowing block starts tomorrow.</p>

<p>The <em>extremely observant</em> may also notice a dearth of non-exercise-related posts hereabouts. The weeks have been fuller than usual lately: Buzzcapture is working up to a (beta) product release, and the <a href="http://www.viaegnatiafoundation.eu/">Via Egnatia</a> Group (which I joined a month ago or so, playing Irish bouzouki) had a couple of concerts (yesterday night at the <a href="http://www.pianola.nl/Pianola_Museum/Homepage.html">Pianola Museum</a>, which is an <em>amazing</em> place). I have some plots and plans, but experience tells me that if I promise them here they&#8217;ll never actually come to fruition, so I&#8217;d better not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/03/18/ows-yer-elf-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>’Ow’s yer ’elf?</title>
		<link>http://www.logophile.org/blog/2012/03/11/ows-yer-elf-3/</link>
		<comments>http://www.logophile.org/blog/2012/03/11/ows-yer-elf-3/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 19:20:10 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ows-yer-elf]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1300</guid>
		<description><![CDATA[Yoga. Once. Sigh.]]></description>
			<content:encoded><![CDATA[<p>Yoga. Once. Sigh.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/03/11/ows-yer-elf-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Inferior decorating</title>
		<link>http://www.logophile.org/blog/2012/03/11/inferior-decorating/</link>
		<comments>http://www.logophile.org/blog/2012/03/11/inferior-decorating/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 18:30:00 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[advice]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1280</guid>
		<description><![CDATA[It&#8217;s another programming post, sorry Mum! Python&#8217;s decorator syntax is an extremely lovely piece of incremental language design. It adds just a tiny bit of syntactic sugar to the language, but that sugar makes you think about structuring your code in ways that I (at least, and apparently plenty of other people) find extremely productive. [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s another programming post, sorry Mum!</p>

<p>Python&#8217;s <a href="http://www.python.org/dev/peps/pep-0318/#current-syntax">decorator syntax</a> is an extremely lovely piece of incremental language design. It adds just a tiny bit of syntactic sugar to the language, but that sugar makes you think about structuring your code in ways that I (at least, and apparently plenty of other people) find extremely productive.</p>

<p>There are two sane ways to write a decorator:<sup>1</sup></p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> decorator<span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
    @functools.<span style="color: black;">wraps</span><span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># do what the decorator does and...</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> wrapper
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> decomaker<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> decorator<span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
        @functools.<span style="color: black;">wraps</span><span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
            <span style="color: #808080; font-style: italic;"># do what the decorator does and...</span>
            <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> wrapper
    <span style="color: #ff7700;font-weight:bold;">return</span> decorator</pre></div></div>


<p>The tl;dr of this article is: always use the second one.</p>

<p><span id="more-1280"></span></p>

<p>That&#8217;s right, I&#8217;m saying you should write the version with <em>more</em> boilerplate, not less. The reason is very simple: the second form allows you to extend your decorator with keyword arguments, while preserving backwards compatibility with any code that doesn&#8217;t know about them. The first form, on the other hand, can only be extended by breaking backward compatibility and requiring all uses of the decorator to be updated.</p>

<p>Let&#8217;s work that through in a little example. Here are two implementations of a simple entry/exit logging decorator.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> log_entry_exit_bare<span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
    @functools.<span style="color: black;">wraps</span><span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Entering %s'</span>, func.<span style="color: black;">func_name</span><span style="color: black;">&#41;</span>        
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">finally</span>:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Exiting %s'</span>, func.<span style="color: black;">func_name</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> wrapper
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> log_entry_exit_args<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> decorator<span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
        @functools.<span style="color: black;">wraps</span><span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Entering %s'</span>, func.<span style="color: black;">func_name</span><span style="color: black;">&#41;</span>        
            <span style="color: #ff7700;font-weight:bold;">try</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">finally</span>:
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Exiting %s'</span>, func.<span style="color: black;">func_name</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> wrapper
    <span style="color: #ff7700;font-weight:bold;">return</span> decorator</pre></div></div>


<p>Now here&#8217;s some code that uses them:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@log_entry_exit_bare
<span style="color: #ff7700;font-weight:bold;">def</span> my_first_function<span style="color: black;">&#40;</span>a=<span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> b <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, a<span style="color: black;">&#41;</span>:
        my_second_function<span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span>
&nbsp;
@log_entry_exit_args<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> my_second_function<span style="color: black;">&#40;</span>a=<span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> b <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>a, <span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        my_first_function<span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span></pre></div></div>


<p>All well and good. Only now, it turns out that what <code>my_second_function</code>
does is important enough to merit an <code>INFO</code> log rather than plain
<code>DEBUG</code>. Easily done:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> log_entry_exit_args<span style="color: black;">&#40;</span>log_level=<span style="color: #dc143c;">logging</span>.<span style="color: black;">DEBUG</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> decorator<span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
        @functools.<span style="color: black;">wraps</span><span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">log</span><span style="color: black;">&#40;</span>log_level, <span style="color: #483d8b;">'Entering %s'</span>, func.<span style="color: black;">func_name</span><span style="color: black;">&#41;</span>        
            <span style="color: #ff7700;font-weight:bold;">try</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">finally</span>:
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">log</span><span style="color: black;">&#40;</span>log_level, <span style="color: #483d8b;">'Exiting %s'</span>, func.<span style="color: black;">func_name</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> wrapper
    <span style="color: #ff7700;font-weight:bold;">return</span> decorator
&nbsp;
@log_entry_exit_args<span style="color: black;">&#40;</span>log_level=<span style="color: #dc143c;">logging</span>.<span style="color: black;">INFO</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> my_second_function<span style="color: black;">&#40;</span>a=<span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> b <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>a, <span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        my_first_function<span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span></pre></div></div>


<p>Crucially, any other code that also uses <code>log_entry_exit_args</code> continues to
work exactly as it did before.</p>

<p>I can&#8217;t work the same magic with <code>log_entry_exit_bare</code>. I can easily
upgrade it to take an argument (rewriting its definition to match
<code>log_entry_exit_args</code>), but then I&#8217;ll have to track down every place it is
used in my code, and add <code>()</code> to each usage. If it&#8217;s in a library I&#8217;ve
released into the wider world, everyone using that library will have to
change their code for the next release that incorporates this change. (Or,
more likely, I won&#8217;t ever make such a release.)</p>

<p>Let&#8217;s face it: if you care enough about code reuse to use decorators at
all, you probably care about this kind of backwards compatibility too. So
don&#8217;t get stuck with inferior decorating.</p>
<p>Notes:</p><ol class="footnotes"><li id="footnote_0_1280" class="footnote">There are less insane ways than I would have expected, because Guido in his wisdom <a href="http://mail.python.org/pipermail/python-dev/2004-August/046711.html">followed a gut feeling</a> and restricted the syntax of decorator expressions.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/03/11/inferior-decorating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>’Ow’s yer ’elf?</title>
		<link>http://www.logophile.org/blog/2012/03/04/ows-yer-elf-2/</link>
		<comments>http://www.logophile.org/blog/2012/03/04/ows-yer-elf-2/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 11:38:13 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ows-yer-elf]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1295</guid>
		<description><![CDATA[This week&#8217;s total: one hour of rowing. Better than nothing, but nothing to be proud of. In a couple of weeks I&#8217;ll be rowing twice a week instead of just once, but I still haven&#8217;t managed to get a running schedule together.]]></description>
			<content:encoded><![CDATA[<p>This week&#8217;s total: one hour of rowing. Better than nothing, but nothing to be proud of. In a couple of weeks I&#8217;ll be rowing twice a week instead of just once, but I still haven&#8217;t managed to get a running schedule together.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/03/04/ows-yer-elf-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Gatekeeper</title>
		<link>http://www.logophile.org/blog/2012/03/03/gatekeeper/</link>
		<comments>http://www.logophile.org/blog/2012/03/03/gatekeeper/#comments</comments>
		<pubDate>Sat, 03 Mar 2012 19:15:41 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[delight]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1288</guid>
		<description><![CDATA[There is a thing I&#8217;m reading, a serialised novel by the name of Constellation Games. It&#8217;s a slightly guilty pleasure, because its protagonist is a programmer in his thirties who gets to visit the Moon and play computer games with space aliens. And yes, I have been enormously enjoying his capsule reviews of alien computer [...]]]></description>
			<content:encoded><![CDATA[<p>There is a thing I&#8217;m reading, a serialised novel by the name of <a href="http://is.gd/constellation_games_serial"><em>Constellation Games</em></a>. It&#8217;s a slightly guilty pleasure, because its protagonist is a programmer in his thirties who gets to visit the Moon and play computer games with space aliens. And yes, I have been enormously enjoying his <a href="(https://twitter.com/#!/ArielBlum)">capsule reviews of alien computer games</a>.<sup>1</sup></p>

<p>So it seems other people are enjoying <em>Constellation Games</em>; people who are even closer to its ideal demographic; people who actually make games. Which is why there now exists <a href="http://www.glorioustrainwrecks.com/node/2556"><em>Gatekeeper</em></a>: a game written by space aliens millions of years ago, which you can play in your browser.</p>

<p>I can&#8217;t say that you should read <em>Constellation Games</em> if you enjoy <em>Gatekeeper</em>. (In fact, if you enjoy actually playing <em>Gatekeeper</em> for more than a few minutes then I&#8217;m a bit worried about you.) But if <a href="https://twitter.com/#!/ArielBlum/status/164040729398751232"><em>Lek Stalker</em></a> and <a href="https://twitter.com/#!/ArielBlum/status/161209029664845827"><em>Ruins Deluxe</em></a> tickle your funnybone, check out <a href="http://www.candlemarkandgleam.com/store/serials/constellation-games-serial/">the rest of the novel</a>. (Also, it is <em>dirt cheap</em>.)</p>
<p>Notes:</p><ol class="footnotes"><li id="footnote_0_1288" class="footnote">I&#8217;m a sucker for <a href="http://www.ommatidia.org/">microfiction</a> and for reviews-as-fiction. Even with <em>real</em> computer games I have been known to let reviews, backstory and a bit of shoulder-surfing substitute for actually playing.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/03/03/gatekeeper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python list incomprehension</title>
		<link>http://www.logophile.org/blog/2012/02/26/python-list-incomprehension/</link>
		<comments>http://www.logophile.org/blog/2012/02/26/python-list-incomprehension/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 19:25:04 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[moaning]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1267</guid>
		<description><![CDATA[Here&#8217;s an oddity of Python that I stumbled upon, which has turned me off doing anything even remotely complicated with list comprehensions. For those following along at home, fire up your ipython now. In &#91;1&#93;: array = &#91;&#91;1,2,3&#93;, &#91;4,5,6&#93;, &#91;7,8,9&#93;&#93; In &#91;2&#93;: &#91; sum&#40;col&#41; for col in array &#93; Out&#91;2&#93;: &#91;6, 15, 24&#93; So far [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an oddity of Python that I stumbled upon, which has turned me off doing anything even remotely complicated with list comprehensions. For those following along at home, fire up your <code>ipython</code> now.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">In <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>: <span style="color: #dc143c;">array</span> = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>, <span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span>, <span style="color: black;">&#91;</span><span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">8</span>,<span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
In <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>: <span style="color: black;">&#91;</span> <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>col<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">array</span> <span style="color: black;">&#93;</span>
Out<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>: <span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">24</span><span style="color: black;">&#93;</span></pre></div></div>


<p>So far so good. Now suppose I want to take the squares of all the elements in <code>array</code>, and flatten the results into a single list. This looks to me like a natural way to do it:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">In <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>: <span style="color: black;">&#91;</span> x<span style="color: #66cc66;">*</span>x <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> col <span style="color: #ff7700;font-weight:bold;">for</span> col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">array</span> <span style="color: black;">&#93;</span></pre></div></div>


<p>However, it is wrong. The result:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">Out <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>: <span style="color: black;">&#91;</span><span style="color: #ff4500;">49</span>, <span style="color: #ff4500;">49</span>, <span style="color: #ff4500;">49</span>, <span style="color: #ff4500;">64</span>, <span style="color: #ff4500;">64</span>, <span style="color: #ff4500;">64</span>, <span style="color: #ff4500;">81</span>, <span style="color: #ff4500;">81</span>, <span style="color: #ff4500;">81</span><span style="color: black;">&#93;</span></pre></div></div>


<p>At this point I should insert a <a href="http://iliketurtles.myshopify.com/blogs/news/5370752-wat-a-funny-look-at-ruby-and-javascript-oddities">picture of a horse in a raincoat holding a cat</a> or something similar.</p>

<p>Let&#8217;s try that one more time, for sanity&#8217;s sake:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">In <span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>: <span style="color: black;">&#91;</span> x<span style="color: #66cc66;">*</span>x <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> y <span style="color: #ff7700;font-weight:bold;">for</span> y <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">array</span> <span style="color: black;">&#93;</span>
<span style="color: #008000;">NameError</span>: name <span style="color: #483d8b;">'y'</span> <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> defined</pre></div></div>


<p>Wat?!</p>

<p>What&#8217;s going on is two distinct oddities of Python, which I have encountered in production code and debugged so that you don&#8217;t have to.</p>

<p>Firstly, loop variables leak into the surrounding scope.<sup>1</sup> It&#8217;s easy to forget this for list comprehensions, since they don&#8217;t overtly contain a loop, but they work just the same. In our example, the <code>col</code> variable that <code>for x in col</code> is using is actually the <em>exit value of <code>col</code> in the previous list comprehension</em>. If you were following along at home and didn&#8217;t do that first, trivial, comprehension (with <code>sum(col)</code>) then chances are you didn&#8217;t have <code>col</code> defined in your <code>ipython</code> session and you hit the error early.</p>

<p>Once we&#8217;ve got that far, it&#8217;s easy to see where the example went wrong: variables are introduced in a list comprehension left-to-right, not right-to-left, so <code>for row in array for x in row</code> is the correct order. We can get here also by mentally creating the nested lists the comprehension represents:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">array</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> row:
        <span style="color: #ff7700;font-weight:bold;">yield</span> x<span style="color: #66cc66;">*</span>x</pre></div></div>


<p>A comprehension lifts the <code>yield</code> line to the front but leaves the loops in the same order.</p>

<p>Still, I think my ordering is a more natural way to represent the expression I&#8217;m trying to capture in code. I had assumed that it came from my long-ago love affair with Haskell, but that&#8217;s actually not the case. The equivalent Haskell expression is:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> array <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span><span style="color: red;">7</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">8</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">9</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span> <span style="color: #06c; font-weight: bold;">in</span> <span style="color: green;">&#91;</span> x<span style="color: #339933; font-weight: bold;">*</span>x <span style="color: #339933; font-weight: bold;">|</span> row <span style="color: #339933; font-weight: bold;">&lt;-</span> array<span style="color: #339933; font-weight: bold;">,</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> row <span style="color: green;">&#93;</span></pre></div></div>


<p>The order the variables appear in is actually just the same.</p>

<p>This doesn&#8217;t raise my hackles the way the Python version does, though. The Haskell code clearly distinguishes the pipe from the comma; the rule you have to know is, before the pipe sees (variables defined) after the pipe, and scope resolution for commas works left-to-right as usual.<sup>2</sup> The weird thing about the Python version is that <code>for &lt;something&gt; in &lt;somewhere&gt;</code> has different scope resolution rules depending on where it is: the first instance in a comprehension resolves the <code>&lt;something&gt;</code> in <code>&lt;somewhere&gt;</code>, but later ones cannot.</p>

<p>So there you go. A case where Python&#8217;s minimalist syntax, which usually I very much appreciate, seems to me to be taking things a bit too far. And (again, just my opinion) a good reason to avoid this kind of list comprehension construction completely. Although in this case the alternative, a wordy <code>map</code>-<code>lambda</code> and an esoteric <code>sum</code>, doesn&#8217;t make me any happier:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">In <span style="color: black;">&#91;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span>: <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> x: x<span style="color: #66cc66;">*</span>x, <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">array</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
Out<span style="color: black;">&#91;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span>: <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">9</span>, <span style="color: #ff4500;">16</span>, <span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">36</span>, <span style="color: #ff4500;">49</span>, <span style="color: #ff4500;">64</span>, <span style="color: #ff4500;">81</span><span style="color: black;">&#93;</span></pre></div></div>

<p>Notes:</p><ol class="footnotes"><li id="footnote_0_1267" class="footnote">All Python programmers should know this about the <code>for</code> loop, since it lets you query the final value of the loop&#8217;s variable after exiting the loop.</li><li id="footnote_1_1267" class="footnote">And the same rules apply elsewhere in Haskell, for instance when pipe is used for guard expressions.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/02/26/python-list-incomprehension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>’Ow’s yer ’elf?</title>
		<link>http://www.logophile.org/blog/2012/02/26/ows-yer-elf/</link>
		<comments>http://www.logophile.org/blog/2012/02/26/ows-yer-elf/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 19:10:21 +0000</pubDate>
		<dc:creator>tikitu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ows-yer-elf]]></category>

		<guid isPermaLink="false">http://www.logophile.org/blog/?p=1286</guid>
		<description><![CDATA[Mission accomplished: the thought of writing this entry has driven me to exercise. Not much exercise, mind you: 20 minutes of yoga this evening. But more than nothing, ergo better than nothing. &#8220;Nothing?&#8221; you ask, &#8220;but whatever happened to running, and to rowing?&#8221; What happened this week is that I got ill. (Possibly helped along [...]]]></description>
			<content:encoded><![CDATA[<p>Mission accomplished: the thought of writing this entry has driven me to exercise.</p>

<p>Not much exercise, mind you: 20 minutes of yoga this evening. But more than nothing, ergo better than nothing.</p>

<p>&#8220;Nothing?&#8221; you ask, &#8220;but whatever happened to running, and to rowing?&#8221; What happened this week is that I got ill. (Possibly helped along by running, and sweating, for 50 minutes in a t-shirt. It&#8217;s not actually really summer yet, turns out.) Tuesday I felt under the weather and skipped rowing, and Wednesday I woke up unable to speak and stayed in bed all day.</p>

<p>I must admit that the illness card had thoroughly played itself out by the weekend, so I have only laziness to blame for not getting back into the saddle. (After my last run my legs ached for days. I&#8217;m reluctant to go through it again, although I know I should.)</p>

<p>In more positive news, coming Tuesday is the last rowing session for this block and I&#8217;ve signed up for twice a week in the following block (back to one-man boats, and I hope by the time it gets warm and Springy to be in a skiff).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logophile.org/blog/2012/02/26/ows-yer-elf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

