<?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>Perlblogs &#187; Uncategorized</title>
	<atom:link href="http://perlblogs.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://perlblogs.com</link>
	<description>Posts from selected Perl bloggers</description>
	<lastBuildDate>Thu, 29 Jul 2010 21:15:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to shuffle a list in Perl</title>
		<link>http://feedproxy.google.com/~r/PerlBuzz/~3/BxLSYp7Uxh0/how-to-shuffle-a-list-in-perl.html</link>
		<comments>http://feedproxy.google.com/~r/PerlBuzz/~3/BxLSYp7Uxh0/how-to-shuffle-a-list-in-perl.html#comments</comments>
		<pubDate>Fri, 28 May 2010 14:32:58 +0000</pubDate>
		<dc:creator>Andy Lester</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[If you've got a list of things in Perl, and you want them in random order, don't try to make up a way to do it yourself. Use the shuffle function in the List::Util module. Say you want a list...]]></description>
			<content:encoded><![CDATA[
        <p>If you've got a list of things in Perl, and you want them in random order, don't try to make up a way to do it yourself.  Use the <tt>shuffle</tt> function in the List::Util module.  Say you want a list of files from a directory:</p>

<pre>
use List::Util qw( shuffle );
my @files = glob( '*' );
@files = grep { -f } @files;
@files = shuffle @files;
</pre>

<p>Of course you can combine that into one expression:</p>

<pre>
use List::Util qw( shuffle );
my @files = shuffle grep { -f } glob( '*' );
</pre>

<p>Or from the command line:</p>

<pre>
perl -MList::Util=shuffle -le'print for shuffle grep {-f} glob("*")'
</pre>

<p>Don't worry that List::Util is a module, because it's a core module that's been included with Perl since 5.7.3</p>

<pre>
$ corelist List::Util

List::Util was first released with perl 5.007003
</pre>

<p>The <tt>shuffle</tt> function is extremely simple, and how here's a little <a href="http://eli.thegreenplace.net/2010/05/28/the-intuition-behind-fisher-yates-shuffling/">article that explains why it works</a>.</p>

        

    <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=BxLSYp7Uxh0:khMgTBTukmo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PerlBuzz?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=BxLSYp7Uxh0:khMgTBTukmo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PerlBuzz?i=BxLSYp7Uxh0:khMgTBTukmo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=BxLSYp7Uxh0:khMgTBTukmo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/PerlBuzz?i=BxLSYp7Uxh0:khMgTBTukmo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=BxLSYp7Uxh0:khMgTBTukmo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PerlBuzz?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PerlBuzz/~4/BxLSYp7Uxh0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/05/28/how-to-shuffle-a-list-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for 2010-05-27 [del.icio.us]</title>
		<link>http://feeds.askbjoernhansen.com/~r/ask/~3/IvRuycMdQf0/ask</link>
		<comments>http://feeds.askbjoernhansen.com/~r/ask/~3/IvRuycMdQf0/ask#comments</comments>
		<pubDate>Fri, 28 May 2010 07:00:00 +0000</pubDate>
		<dc:creator>Ask Bjørn Hansen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://del.icio.us/ask#2010-05-27</guid>
		<description><![CDATA[
Migrate Paravirtualized Xen to KVM under RHEL
]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://www.gloudemans.info/migrate-paravirtualized-xen-to-kvm-under-rhel/">Migrate Paravirtualized Xen to KVM under RHEL</a></li>
</ul><img src="http://feeds.feedburner.com/~r/ask/~4/IvRuycMdQf0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/05/28/links-for-2010-05-27-del-icio-us/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Anethics of Innovation and Disclosure</title>
		<link>http://www.modernperlbooks.com/mt/2010/05/the-anethics-of-innovation-and-disclosure.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/05/the-anethics-of-innovation-and-disclosure.html#comments</comments>
		<pubDate>Mon, 24 May 2010 19:35:42 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Whenever someone suggests that innovation is the sine qua non of anything in the world of technology, lock your doors, put one hand on your wallet, and send the kids inside. (Me, I also close the tab and delete the...]]></description>
			<content:encoded><![CDATA[
        <p>Whenever someone suggests that innovation is the sine qua non of
<em>anything</em> in the world of technology, lock your doors, put one hand on
your wallet, and send the kids inside.  (Me, I also close the tab and delete
the email.)</p>

<p>Consider your privacy.  Consider whether a company whose sole business
purpose is to sell targeted advertising by extracting, sharing, and mining
personal information from millions of people.  (Do I mean Google or Facebook?)
A fan of free markets and free information might say "Whether any individual
finds that objectionable, an informed citizen should have the right to decide
whether to participate."</p>

<p>The assumption is that citizens should be able to know what information the
business shares, with whom, and why.  It's easy to understand why.  Even though
it's funny to laugh at a petty criminal caught by posting a stupid update which
gives the authorities reasonable suspicion of a crime, it's unsettling to
imagine an abused and estranged spouse who's dutifully followed the guidelines
for not allowing personal information to escape a hand-vetted circle of
trustworthy family and friends fall victim to an unannounced, opt-out rule
change which allows the abuser to perpetuate the abuse.</p>

<p>The parallel to Perl is subtle, but important.  <a
href="http://www.modernperlbooks.com/mt/2009/02/backwards-compatibility-is-technical-debt.html">If
you want to improve your software, sometimes you have to make incompatible
changes</a> (or learn how to predict the future, or write software so trivial
that you always get it right the first time), but <a
href="http://www.modernperlbooks.com/mt/2009/05/writing-perl-5s-support-policy.html">changing
the world out from under users is irresponsible and unethical</a>.</p>

<p>The difference between managing your privacy and safety in a world where
mass communication is cheap and easy and between having to change the use of a
long deprecated feature is vast, but in both cases there's a simple ethical
concern: retroactive and arbitrary and unannounced and forced changes are wrong.</p>

<p>That's why <a href="http://radar.oreilly.com/2010/05/my-contrarian-stance-on-facebook-privacy.html">My Contrarian Stance on Facebook and Privacy</a> is very, very wrong:</p>

<blockquote><em>[Let's] not make privacy a third rail issue, pillorying any company that makes a mistake on the privacy front. If we do that, we'll never get the innovation we need to solve the thorny nest of issues around privacy and data ownership that are intrinsic to the network era.</em></blockquote>

<p>Don't let the shiny of the Internet hero de jure fool you.  The technical world needs less "innovation".  (I'll take less of the kind of "innovation" which suggests that if I didn't want to share information publicly last month, I suddenly want to this month without you even asking.)  The technical world needs more grownups who don't get distracted by multibillion market caps, the inherent sexiness of enterprise software, and whatever His Jobs announces next week.  The technical world needs people who treat other people ethically.  If that means pillorying entities which act unethically, then so be it.</p>

        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/05/24/the-anethics-of-innovation-and-disclosure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What I’m working on in Perl</title>
		<link>http://www.dagolden.com/index.php/773/what-im-working-on-in-perl/</link>
		<comments>http://www.dagolden.com/index.php/773/what-im-working-on-in-perl/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 22:23:03 +0000</pubDate>
		<dc:creator>dagolden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ironman]]></category>
		<category><![CDATA[perl programming]]></category>

		<guid isPermaLink="false">http://www.dagolden.com/?p=773</guid>
		<description><![CDATA[Andy just asked &#8220;What are you working on in Perl?&#8221; but rather than reply in a comment, I thought it would be a good Ironman post of my own, so here we go:

CPAN Meta Spec version 2 &#8212; I released the final spec and will soon be looking to rally toolchain developers to implement it.
CPAN [...]]]></description>
			<content:encoded><![CDATA[<p>Andy just asked <a href="http://perlbuzz.com/2010/04/what-are-you-working-on-in-perl.html">&#8220;What are you working on in Perl?&#8221;</a> but rather than reply in a comment, I thought it would be a good Ironman post of my own, so here we go:</p>
<ul>
<li>CPAN Meta Spec version 2 &#8212; I <a href="http://www.dagolden.com/index.php/759/cpan-meta-spec-version-2-released/">released the final spec</a> and will soon be looking to rally toolchain developers to implement it.</li>
<li>CPAN Testers 2.0 &#8212; I <a href="http://www.dagolden.com/index.php/743/cpan-testers-2-0-beta-test-update/">launched CPAN Testers 2.0 Beta site</a>, the eventual replacement for the current practice of sending CPAN Testers reports over email and I&#8217;m continuing to monitor it, tweak it and fix little bugs</li>
<li>Perl 5 core development &#8212; I&#8217;m scheduled to be the release-engineer for Perl 5.13.3 in July.  In addition, my goals for Perl 5.13 include getting HTTP support for CPAN clients into the core, simplifying CPAN configuration further and implementing CPAN Meta.</li>
<li>Drafting a formal description of the expectations for Perl build systems that use Build.PL.  Right now it&#8217;s only Module::Build, but it could be other things in the future.  I&#8217;ve started <a href="http://github.com/dagolden/cpan-api-buildpl">a very rough draft</a> of what cpan clients should expect Build.PL (and the resulting Build) to support.</li>
<li>Dist::Zilla &#8212; I&#8217;ve been converting my distributions over to Dist::Zilla as I work on them.  It&#8217;s a huge time saver for me (something I hope to blog about more later).  I&#8217;ve also implemented some plugins recently: <a href="http://search.cpan.org/perldoc?Dist::Zilla::Plugin::CheckExtraTests">DZP::CheckExtraTests</a>, <a href="http://search.cpan.org/perldoc?Dist::Zilla::Plugin::BumpVersionFromGit">DZP::BumpVersionFromGit</a> and <a href="http://search.cpan.org/perldoc?Dist::Zilla::Plugin::Twitter">DZP::Twitter</a></li>
<li>I <a href="http://www.dagolden.com/index.php/739/modulebuild-repository-migrated-to-git/">converted the Module::Build repository</a> to git to encourage more contributions and to make it easier to apply them.  I released a development version, <a href="http://search.cpan.org/~dagolden/Module-Build-0.36_08/">0.36_08</a>, with some recent additions.</li>
</ul>
<p>Here are several other things released to CPAN in the last couple months not mentioned above:</p>
<ul>
<li><a href="http://search.cpan.org/perldoc?File::chdir">File-chdir-0.1003</a> &#8212; maintenance release for 5.13.X</li>
<li><a href="http://search.cpan.org/perldoc?Acme::Module::Build::Tiny">Acme-Module-Build-Tiny-0.04</a> &#8212; a half-serious replacement for Module::Build</li>
<li><a href="http://search.cpan.org/perldoc?Version::Next">Version-Next-0.001</a> 	&#8211; increment module version numbers simply and correctly</li>
<li><a href="http://search.cpan.org/perldoc?ExtUtils::CBuilder">ExtUtils-CBuilder-0.2703</a> &#8212; better Windows support for MSVC</li>
<li><a href="http://search.cpan.org/perldoc?Net::Amazon::Config">Net-Amazon-Config-0.001</a> &#8212; simple utility to manage Amazon Web Services credentials</li>
<li><a href="http://search.cpan.org/perldoc?CPAN::Visitor">CPAN-Visitor-0.001</a> &#8212; generic traversal of distributions in a local CPAN  or minicpan repository</li>
<li><a href="http://search.cpan.org/perldoc?Capture::Tiny">Capture-Tiny-0.07</a> &#8212; the only output capturing program you should ever need</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dagolden.com/index.php/773/what-im-working-on-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>State and the Syntax of Encapsulation</title>
		<link>http://www.modernperlbooks.com/mt/2010/04/state-and-the-syntax-of-encapsulation.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/04/state-and-the-syntax-of-encapsulation.html#comments</comments>
		<pubDate>Fri, 23 Apr 2010 23:32:51 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
        More and more I realize that good software design minimizes the amount of things you have to care about at any one time.  Well-designed programs take advantage of abstraction possibilities of languages and libraries to model the problem and it...]]></description>
			<content:encoded><![CDATA[
        <p>More and more I realize that good software design minimizes the amount of things you have to care about at any one time.  Well-designed programs take advantage of abstraction possibilities of languages and libraries to model the problem and its solution in the most effective way.  Well-designed languages minimize the syntactic concerns necessary to produce those abstractions.</p>

<p>I unsurprising news, the default Perl 5 object system shows its limits in that you have to think about Perl 5 reference syntax <em>and</em> objects <em>and</em> encapsulation, genericity, abstraction, and polymorphism all at once.  <a href="http://www.modernperlbooks.com/mt/2010/01/subtle-encouragement-toward-correctness.html">Moose encourages people to do the right thing</a> by providing abstractions that encapsulate the concerns of other levels of abstraction.  Inside-out objects did something similar.</p>

<p>I realized this yesterday when writing about <a
href="http://perldoc.perl.org/functions/state.html">the <code>state</code>
feature introduced in Perl 5.10</a>.  If you're a fan of minimalist languages
which provide one and only one obvious way to do things, you'll hate this
explanation, but at least you'll know why you're wrong.</p>

<p><code>state</code> declares a lexical variable which maintains its state
even after control flow leaves its lexical scope.  In other words, these two
snippets of code are almost entirely equivalent:</p>

<pre><code>
# the closure approach
{
    my $count = 0;

    sub add_user
    {
        my ($user, %data) = @_;
        $data{user_id}    = $count++;
        ...
    }
}

# the state approach
use feature 'state';

sub add_user
{
    state $count      = 0;

    my ($user, %data) = @_;
    $data{user_id}    = $count++;
    ...
}</code></pre>

<p>The one potential difference is that the initialization of
<code>$count</code> in the first example must take place before the first call
to <code>add_user()</code>.</p>

<p>If you're careful to avoid that tiny potential trap, you can achieve the
same effect with the closure code.  Scheme and Python and even Java fans
rejoice for a moment.  Okay, that's long enough.</p>

<p>The problem is that&mdash;just as with arguing that you don't need <code>fold</code> because you have a <code>for</code> loop with iteration&mdash;that line of thinking ignores the fact that the syntactic overhead necessary to make the former example work is too high.  Adding a single keyword to achieve the same semantics <em>and</em> avoid that tiny little trap also makes the resulting code more expressive.  It's more declarative.</p>

<p>There's nothing wrong with the goal of a language with a minimal feature
set.  That's a fine goal, but it can't be the most important goal, and it can't
be a goal in isolation.  That's because sometimes adding a feature lets you
remove unnecessary scaffolding.</p>

<p>I believe that <a href="http://www.modernperlbooks.com/mt/2009/04/attributes-of-elegant-perl-concision.html">it's better to pursue concision than artificial simplicity</a> in program and language design.</p>

        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/04/24/state-and-the-syntax-of-encapsulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Thing about Volunteers and Civility</title>
		<link>http://www.modernperlbooks.com/mt/2010/04/the-thing-about-volunteers-and-civility.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/04/the-thing-about-volunteers-and-civility.html#comments</comments>
		<pubDate>Wed, 21 Apr 2010 20:46:34 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
        The thing about volunteers is that they don't have to do what they're doing.  If you're getting paid to hang out in an IRC channel and answer questions all day, that's one thing.  If you're hanging out on an IRC channel all day because you wan...]]></description>
			<content:encoded><![CDATA[
        <p>The thing about volunteers is that they don't have to do what they're doing.  If you're getting paid to hang out in an IRC channel and answer questions all day, that's one thing.  If you're hanging out on an IRC channel all day because you want to, that's another.</p>

<p>The thing about volunteers writing software is that they don't have to do it.  The same goes for volunteers writing documentation or reporting bugs or asking questions about how to use or install or configure that software.</p>

<p>The thing about the Perl community is that almost no one gets paid solely for participating in the Perl community.  Sure, you can volunteer for a while to earn the cachet and the right to apply for a TPF grant at a fraction of the going consulting rate to justify continuing to work on the unpleasant parts of a project, but you're still effectively a volunteer.</p>

<p>The thing about volunteers is if it's not worth their time or energy or health or sanity or happiness to keep volunteering, they can walk away whenever they want.  They have no obligation to continue to do what they do.  Not even their sense of devotion or duty or guilt or community camaraderie should compel them to continue on projects that aren't worth their investment of time, and that's more than okay.</p>

<p>The thing about volunteers is that you can't force them to do anything.  You can't force them to have your priorities.  You can't force them to work to your schedule.  You can't force them to work on your project and you can't force them to care about what you care about.  They'll do what they want to do when they want to do it and you either deal with it or you don't.</p>

<p>The thing about volunteers is that it's rare to have too many and it's far too common to have far too few.  Thus healthy projects spend time and effort recruiting volunteers and keeping volunteers around and guiding the interests and energy and time of volunteers in productive ways, not only by making their projects pleasant and useful but by removing distractions and unpleasantness from their communitites.</p>

<p>The thing about volunteers is that for every one willing to take the abuse and hostility from a few people, you can't tell how many orders of magnitude more potential volunteers find that hostility and abuse so distasteful that they refuse to consider the possibility that it's worth their time to contribute.</p>

<p>The thing about volunteers is that if you allow certain parts of the community to fester and to grow toxic, you're well on your way to having fewer and fewer volunteers who grow more bitter and eventually become a tiny little cluster of angry, angry people who can't do anything productive.</p>

<p>The thing about volunteers is that it doesn't have to be this way.</p>

<p>Certain Perl IRC channels don't have to be seething cauldrons of rage from burned out system administrators who castigate anyone who doesn't know the secret rituals and wordings of arcane rituals to identify themselves as insiders.</p>

<p>Certain Perl forums don't have to devolve into arguments over whose web framework stole which idea from some other place, or whether it's clear that anyone who does or does not use one CPAN dependency or another has parents with specific unpleasant characteristics.</p>

<p>Certain Perl mailing lists don't have to debate whether people who work on one version of Perl or another are hateful fools whose only goal in life is to destroy everything good and sunshiney and organic.</p>

<p>Certain Perl blogs don't have to have comments accusing other volunteers of being liars or thieves or people of negotiable affection because said volunteers disagree on project management styles.</p>

<p>I suppose it's easier to destroy than to create, and it's easier to prove that you're right by demonstrating your scathing verbal wit with a keyboard, and it's easier to believe that you've won an argument if you reduce the other person to a cardboard cutout of simplistic, ridiculous beliefs.  It's also easy to justify your decision to spread hostility if you can overlook the fact that the person you're castigating is a human being with complex motivations, goals, dreams, aspirations, beliefs, and emotions.</p>

<p>The thing about volunteers is that they don't owe you a thing.</p>

<p>If you want a Perl community full of hostile people who jump to hasty conclusions, who are willing to nitpick and debate the specific meaning of words than to understand what other people mean, and who are willing to throw wild accusations of crazy, hateful motives around, then you have an easy task.  Just say nothing.  Let it fester.</p>

<p>Me, I don't think that's the way to encourage a healthy community.  After
all, how silly is it to argue over how some other volunteer spends his or her
time?  Yet isn't that what we're doing?</p>

<p>Maybe if more of us speak up when we see this abuse and hostility, maybe we can discourage it.  Maybe we can encourage people to try to understand and listen more, or at least to disagree politely if they must disagree.  Maybe we can help people unwilling to be civil to find better hobbies than abusing other volunteers.   Maybe we can make the Perl community and our IRC channels and our mailing lists and our forums and our comment sections places where potential volunteers <em>want</em> to participate because they know that we appreciate novices and we appreciate volunteers and we don't all have to do the same things or want the same things or agree on the same things to treat each other with respect.</p>

<p>After all, we're all trying to build great software to solve problems.  Why should we borrow trouble?</p>

        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/04/21/the-thing-about-volunteers-and-civility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three-arg open() (Migrating to Modern Perl)</title>
		<link>http://www.modernperlbooks.com/mt/2010/04/three-arg-open-migrating-to-modern-perl.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/04/three-arg-open-migrating-to-modern-perl.html#comments</comments>
		<pubDate>Mon, 19 Apr 2010 21:55:07 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
        I can forgive novices for writing clunky Perl code because they're following the example of far too many books and tutorials.  If you date the Perl Renaissance to the year 2000 (as I do), then you can identify code written before that point an...]]></description>
			<content:encoded><![CDATA[
        <p>I can forgive novices for writing clunky Perl code because they're following the example of far too many books and tutorials.  If you date the <a href="http://www.modernperlbooks.com/mt/2009/07/milestones-in-the-perl-renaissance.html">Perl Renaissance</a> to the year 2000 (as I do), then you can identify code written before that point and code written after that point.</p>

<p><em>If</em> modern Perl is safer or easier or clearer or simpler or cleaner to write than legacy Perl, then it should be possible to explain how and why to use modern features in lieu of older features.</p>

<p>For example....</p>

<h2><strong>Three-argument <code>open()</code></strong></h2>

<p>There are two forms of the <code>open()</code> function in Perl 5.  The modern version takes three arguments: the filehandle to open or vivify, the mode of the filehandle, and the name of the file.</p>

<p>The legacy version has two arguments, only the filehandle and the name of the file.  The mode of the file comes from the filename; if the filename starts (or ends) with any of several special characters, <code>open()</code> parses them off and uses them.</p>

<p>If you accidentally use a filename with those special characters with the
two-arg form of <code>open()</code>, your code will not behave as you expect.
This is especially a problem if you're not careful about sanitizing user input,
and if any user input ever becomes part of a filename.  Consider:</p>

<pre><code>open my $fh, "&gt;$filename" # INSECURE CODE; do not use
    or die "Can't write to '$filename': $!\n";</code></pre>

<p>While this code appears to open <code>$filename</code> for writing, an
insecure <code>$filename</code> could start with <code>&gt;</code> to force
appending mode, or <code>-</code> to open STDOUT (though I suspect you have to
work really hard to force this).  Likewise, code without any explicit mode in
the second and final parameter is susceptible to any special mode
characters.</p>

<p>Extracting file modes into a separate parameter to this function prevents
Perl from parsing the filename at all and removes the possibility for this
unintentional behavior.  As Damian Conway has mentioned, using a separate file
mode parameter also makes the intention of the code clearer:</p>

<pre><code>open my $fh, '&gt;', $filename # safer and clearer
    or die "Can't write to '$filename': $!\n";</code></pre>

<p>The modern version of this code is safer and clearer, and it's been
available since Perl 5.6.0, released on 22 March 2000.  There's no reason not
to use the modern version.  (If you need your code to run on Perl 5.005, try a
core module such as <a
href="http://search.cpan.org/perldoc?IO::Handle">IO::Handle</a>.  If you need
your code to run on older versions of Perl 5, you have my sympathy.)</p>
        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/04/19/three-arg-open-migrating-to-modern-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Friction</title>
		<link>http://www.modernperlbooks.com/mt/2010/04/removing-friction.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/04/removing-friction.html#comments</comments>
		<pubDate>Fri, 16 Apr 2010 20:00:18 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
        I migrated one of my CPAN distributions to Dist::Zilla yesterday.  This seems like a little thing, but all of the Dzil plugins I use in the distribution remove one small step from managing the distribution.  I don't have to update version numb...]]></description>
			<content:encoded><![CDATA[
        <p>I migrated one of my CPAN distributions to <a href="http://dzil.org/">Dist::Zilla</a> yesterday.  This seems like a little thing, but all of the Dzil plugins I use in the distribution remove one small step from managing the distribution.  I don't have to update version numbers.  I don't have to update the <em>README</em> file.  I don't have to worry about copyright information, or specifying dependencies, or keeping my metadata files up to date.</p>

<p>I don't even have to use the PAUSE website to upload a new distribution.</p>

<p>In similar fashion, I migrated that distribution to Github.  <a href="http://moritz.faui2k3.org/">Moritz Lenz</a> had found and fixed a couple of bugs.  I'd already set up the distribution such that test cases were reasonably easy to add, and the code was simple enough that the fixes were fairly obvious.  Moritz forked my distribution from <a href="http://github.com/gitpan">Gitpan</a>.</p>

<p>I had my own Git clone of that repo, where merging Moritz's changes took a
couple of commands.  Releasing a new version with those changes was almost
immediate.  After that, I converted my personal SVK over SVN repository to Git,
made my own Git repository on Github, and cherry-picked the commits from my
original fork to my new repository.</p>

<p>I never lost history.  I never had to edit a conflict.  I never had to ask Moritz to resubmit a patch.  The only distribution editing I did was to remove unnecessary files from my repository and to ask Dzil to generate them.</p>

<p>I knew all of the existing behavior of my distribution continued to work, because all of the tests passed.  I knew my distribution would work properly with PAUSE and the CPAN because all of <code>Dist::Zilla</code>'s tests worked.  I also know that if any problems arise, the difficulty of fixing them is solely the difficulty of finding and fixing the bugs, not of managing the process of fixing the bug and managing repositories or verifying previous behavior or wrangling uploads or editing metadata in files manually.</p>

<p>The distance between fixing a bug and distributing a new version to users has shortened, and that path is now smoother.</p>

<p>You don't have to use Git or Github or Dzil or Perl.  Plenty of other good tools exist to manage complexity or to make complexity go away.  Yet isn't that what we should do as programmers?  We find barriers and difficulties and obstacles and we eliminate or minimize them, not solely because the new versions have a novelty factor or have greater elegance and aesthetic appeals, but because the relentless process of simplifying removes artificial complexity and structural scaffolding that all too often distracts from the real problems we need to solve.</p>

<p>After all, Moritz and I want to publish an attractive, informative, readable, accurate book about Rakudo Perl 6.  Software is just the means by which we do so.</p>
        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/04/16/removing-friction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Correct or Compatible, Pick One</title>
		<link>http://www.modernperlbooks.com/mt/2010/04/correct-or-compatible-pick-one.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/04/correct-or-compatible-pick-one.html#comments</comments>
		<pubDate>Wed, 14 Apr 2010 20:39:21 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
        Try::Tiny shouldn't become a core module in Perl 5, because it works around a series of infelicities of implementation.

If Perl 5 were to address this problem, someone would have to rethink several well-established, fundamental design and imp...]]></description>
			<content:encoded><![CDATA[
        <p><a href="http://www.modernperlbooks.com/mt/2010/04/dont-core-your-workarounds.html"><code>Try::Tiny</code> shouldn't become a core module in Perl 5</a>, because it works around a series of infelicities of implementation.</p>

<p>If Perl 5 were to address this problem, someone would have to rethink several well-established, fundamental design and implementation and language decisions.  Someone would have to test them, not just with all of the core tests, but with all of the CPAN.  Someone would have to document the changes and hope that the updated documentation would eventually make its way into new books on Perl 5 as well as all of the example code on the Internet.  Someone would have to update existing code, especially on the CPAN, to take advantage of the new features.</p>

<p>This is all possible.  It's happened before.  Code people care about gets
maintained, and if new features are useful in that code, people will update it
to take advantage of new features.  Similarly, features removed from a language
or library get removed from programs when they update to new versions of that
language or library.  None of this is new and none of this is surprising.</p>

<p>The real problem in the case of exceptions and scope exit semantics in Perl 5 is that the initial design didn't anticipate the possible edge cases which make the feature (occasionally) unreliable.  You can design all of the formal semantics of a language as much as you want.  You can spend ten years writing a specification.  You can prove the initial implementation with formal methods.  Yet as soon as users start doing things you didn't expect, you'll run into cases the specification and design and intent don't cover, and then you have a difficult question.</p>

<p><em>If</em> someone changed the way scope handling and exit and call stack unwinding worked in Perl 5, such that exceptions could never get lost and lexical destruction always occurred in a predictable order and return values propagated to the appropriate places, <a href="http://search.cpan.org/perldoc?Try::Tiny">Try::Tiny</a> would be unnecessary...</p>

<p>... and someone (probably that same someone) would have to provide a
compatibility mechanism for all of the existing code which relies on specific
details&mdash;documented and otherwise&mdash;of scope handling and leave
semantics and destruction ordering as it exists in Perl 5.12 right now, to give
people time to migrate to the new system and to notify them that the old system
is deprecated and to find design and implementation infelicities in the new
system.</p>

<p>If reading that paragraph wearies you, imagine how much more doing all of that would be.</p>

<p>Granted, fixing scope handling and destruction ordering and leave semantics
is as big a task in Perl 5 (or any language) as anything else.  It's doable,
from the technical side.  Yet how much sixteen year old code needs to change to
achieve it, and how many assumptions in the billions of lines of code written
in the past sixteen years need to change to make it work?  Worse yet, this
isn't a <a href="http://moose.perl.org/">Moose</a> situation, where an obvious
improvement is available to anyone with a CPAN client and a few minutes to read
a tutorial.</p>

<p>I don't mean to dishearten anyone.  The edge cases for which <code>Try::Tiny</code> exists are rare, and you can write Perl 5 code for years without encountering them.  It's an easy module to use and it shields you from most of the damage.</p>

<p>Even so, fixing bugs the right way&mdash;making them impossible to encounter&mdash;is not always easy.  You don't often get a fresh start in software, but sometimes that's exactly what you need.</p>

        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/04/14/correct-or-compatible-pick-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Core Your Workarounds</title>
		<link>http://www.modernperlbooks.com/mt/2010/04/dont-core-your-workarounds.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/04/dont-core-your-workarounds.html#comments</comments>
		<pubDate>Mon, 12 Apr 2010 18:48:25 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
        Exception handling in Perl 5 seems easy, until you realize all of the things that could possibly go wrong between the time your eval BLOCK exits and you check the global variable $@.  Fortunately, Try::Tiny hides most of the difficult details ...]]></description>
			<content:encoded><![CDATA[
        <p>Exception handling in Perl 5 seems easy, until you realize all of the things that could possibly go wrong between the time your <code>eval</code> BLOCK exits and you check the global variable <code>$@</code>.  Fortunately, <a href="http://search.cpan.org/perldoc?Try::Tiny">Try::Tiny</a> hides most of the difficult details from you, so you can concentrate on writing good exception handlers without worrying about all of the special cases that may eventually confuse and concern you.</p>

<p>It was inevitable to see <a href="http://www.nntp.perl.org/group/perl.perl5.porters/2010/03/msg158109.html">a suggestion to put <code>Try::Tiny</code> in the core</a>, and the resulting discussion of conflicting goals and motivations and reasons to remove things from the core and suggestions of other things to put in the core was even more inevitable.  (If you've read one thread like this before, you've read one too many.)</p>

<p><a href="http://blog.woobling.org/">Yuval Kogman</a>, the author of <code>Try::Tiny</code> responded the other day, saying that <a href="http://www.nntp.perl.org/group/perl.perl5.porters/2010/04/msg158764.html"><code>Try::Tiny</code> is a band-aid, not a solution</a>.</p>

<p>Here's a design principle.</p>

<p>Exception handling in Perl 5 is difficult to use with complete safety and correctness.  You have to beware of a few strange edge conditions that, in most software, never occur.  When they do occur, they're strange and difficult because of the semantics of how scopes and exceptions and destruction and call-graph unwinding occur in Perl 5.</p>

<p>Making <code>Try::Tiny</code> a core module&mdash;and recommending it as the core-approved way of handling exceptions in Perl 5&mdash;enshrines that workaround as well as the flaws of implementation around which it works.  The module exists as an alternative to a proper fix at the language and implementation levels.  It's a patch.  It's a workaround.  It's not a controversial extension to the language that some people may want and others don't.  Instead, it's a makeshift that offers more safety and correctness and abstractions around those relatively unknown idioms to help people write better programs.</p>

<p>In the same way, <a href="http://search.cpan.org/perldoc?signatures">signatures</a> is a workaround for the lack of a feature in Perl 5 as much as <a href="http://search.cpan.org/perldoc?MooseX::Declare">MooseX::Declare</a> is a workaround for the lack of succinct boilerplate-reducing features in Perl 5.</p>

<p>Making extensions <em>possible</em> doesn't relieve language designers and implementors from the responsibility of providing <em>necessary</em> features and abstractions.</p>

<p><a href="http://search.cpan.org/perldoc?Devel::Declare">Devel::Declare</a>
is, in general, a good thing because it allows experimentation with language
features and ideas that may be useful in the core eventually, or may be useful
in specific domains, or may be unsuccessful, but at least provide that data.
Safety and ease of experimentation help develop communities of invention and
evolution.</p>

<p>... but you have to recognize workarounds for what they are.  Next time,
I'll explain the practical consequences of this tension.</p>
        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/04/12/dont-core-your-workarounds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
