<?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>Coyote Tracks &#187; Perl</title>
	<atom:link href="http://kagan.mactane.org/blog/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://kagan.mactane.org/blog</link>
	<description>The prints of an Internet-enabled coyote.</description>
	<lastBuildDate>Tue, 31 Jan 2012 03:26:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>So Why Isn&#8217;t Perl My Favorite Programming Language?</title>
		<link>http://kagan.mactane.org/blog/2009/08/26/so-why-isnt-perl-my-favorite-programming-language/</link>
		<comments>http://kagan.mactane.org/blog/2009/08/26/so-why-isnt-perl-my-favorite-programming-language/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 17:50:58 +0000</pubDate>
		<dc:creator>Kai MacTane</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://kai.mactane.org/blog/?p=115</guid>
		<description><![CDATA[A good long while ago, I tried doing an exercise that I was considering making into a standard job interview question: &#8220;For each of your &#8216;languages of choice&#8217;, tell me 5 things you like about the language, and 5 things you dislike about it.&#8221; My languages of choice at the time were Perl, PHP, and [...]]]></description>
			<content:encoded><![CDATA[<p>A good long while ago, I tried doing an exercise that I was considering making into a standard job interview question: &#8220;For each of your &#8216;languages of choice&#8217;, tell me 5 things you like about the language, and 5 things you dislike about it.&#8221; My languages of choice at the time were Perl, PHP, and JavaScript, and my answers quickly showed me why this was <em>not</em> the best interview question:
</p>
<p>It was far too easy to come up with dislikes, and not so easy to come up with likes. It was a perfect example of the adage that &#8220;Every programming language sucks, but some of them suck more.&#8221;
</p>
<p>That said, the one language that scored more likes than dislikes, for me, was Perl. Here are some of the things I like about Perl:<span id="more-115"></span>
</p>

<ol>
	<li>Different sigils improve readability. The only data types that matter in Perl are easily distinguished. While we&#8217;re at it, ensigillizing your variables means you can stick them in print statements without having to step out of the quotes: <code>print "foo equals $foo and bar equals $bar"</code> is pretty easy. A sigil-less language like JavaScript requires <code>print "foo equals " + foo + " and bar equals " + bar</code> so the interpreter knows when to print the value of <code>foo</code> and when to just print the string &#8220;foo&#8221;.</li>
	<li>Scalar vs. list context means the language effectively doubles its potential function namespace, because each function can (potentially) return one thing in scalar context and another thing in list context. (For example, the &#8220;grep&#8221; function can either return a list of matches, or just the number of matches it found.)</li>
	<li>The language is compact. (Contrast this with PHP&#8230;)</li>
	<li>Function names are generally chosen pretty well, so that an experienced programmer can generally get a good idea of what the function does. (Contrast this with, for example, Prototype.js&#8217; <code>Enumerable.include()</code> method. This name looks&nbsp;&mdash; at least to me&nbsp;&mdash; like it should <em>do something</em>, but instead, it actually returns a Boolean based on whether the Array, Hash, or Object in question contains the given property. I understand this is based on Ruby&#8217;s <code>Array.include?</code> method, but the removal of the question mark results in a confusing name.)</li>
	<li>Nearly all built-in functions have default arguments, which are sensibly chosen. For example, if no array is passed to <code>shift()</code>, it will shift <code>@ARGV</code>. By default, <code>print()</code> prints <code>$_</code>, and pattern matches match on <code>$_</code>.</li>
	<li>The presence and uses of the <code>$_</code> variable are reminiscent of pronouns in human languages. Once I&#8217;ve referred to, for example, &#8220;John&#8221;, I don&#8217;t have to keep calling John &#8220;John&#8221; every time I want to talk about John. I can just say &#8220;him&#8221;. Similarly, once I&#8217;ve set up, for example, a <code>while&nbsp;(&lt;FILEHANDLE&gt;)</code> construct, I don&#8217;t have to refer to each line as <code>$line</code>. I can go ahead and pattern match on <code>$_</code> without having to construct an extra variable. And since the pattern-match operator operates on <code>$_</code> by default, I don&#8217;t even need to mention it&#8230; This is huge. This is a core part of what makes Perl Perl. Effectively, <em>it has pronouns</em>.</li>
	<li>The language doesn&#8217;t enforce any particular programming paradigm. It easily supports procedural, object-oriented, and functional programming. It has anonymous functions, first-class functions, and closures.</li>
	<li>Regex extensions like \b, \d, and \s, and especially \W, \D, and \S, make my life easier. (I continually miss them when working with non-Perl regexes, such as egrep.)</li>
	<li>The standard substring-finding mechanism (&ldquo;do a regex match&rdquo;) returns Boolean. This stands in stark contrast to the more usual <code>substr()</code>, which tries to do too much: it returns the position at which the substring was found, <em>or</em> an out-of-band value (such as -1 or Boolean false) if the substring wasn&#8217;t found. This means that if I just want to know if the substring was in there or not (but I don&#8217;t care where it was), I have to do an <em>extra</em> check against that out-of-band value. For example, I have to do <code>if (false !== substr($haystack, $needle))</code> in PHP, or the equivalent <code>if (haystack.match(/needle/) != -1)</code> in JavaScript. Note that JavaScript, even though it uses a regex match, still returns a positional integer instead of a strict Boolean! This gives me <em>too much</em> information, making me hang an ugly-looking &ldquo;!=&nbsp;-1&rdquo; off the end for no benefit.</li>
</ol>

<p>By the way, just to round out the list, here are a few of the things I dislike about Perl:
</p>

<ol>
	<li>You have to manually unpack and assign function arguments? What was Larry Wall <em>thinking</em>?!? I&#8217;m okay with &#8220;sub&#8221; instead of &#8220;function&#8221; as the function declaration keyword (just barely), but not being able to declare the argument names as part of the function definition? That&#8217;s just bizarre and weird, and it hurts every time I have to write a separate <code>my ($foo, $bar, $baz) = @_;</code> line after the <code>sub foobar&nbsp;{</code> part.</li>
	<li>And in every single class method, you need to manually unpack a reference to <code>$self</code>! This is, I&#8217;m quite sure, intimately related to the previous problem. But it&#8217;s another context in which I keep encountering the problem. Stupid boilerplate like the existence of <code>my $self = shift;</code> in every single method everywhere should simply not ever exist; it should be abstracted out and taken care of automatically.</li>
</ol>

<p>At one point, I had high hopes that Perl 6 would fix these problems. At this point? The momentum has been lost; the interest in Perl has shifted to other languages (largely Ruby and Python). I recognize that Larry Wall and the Perl team are proceeding at their own pace, and that they&#8217;re more concerned with doing it <em>right</em> than with doing it quickly. And I appreciate that.
</p>
<p>But they&#8217;ve taken <em>so</em> long that I doubt anyone really cares much any more. Perhaps Perl&nbsp;6 will manage to reawaken interest in Perl&#8230; but if so, it&#8217;ll be starting from scratch, rather than building on Perl&nbsp;5&#8242;s preexisting popularity. Which is kind of a shame, because there&#8217;s so much to like about Perl.
</p>

]]></content:encoded>
			<wfw:commentRss>http://kagan.mactane.org/blog/2009/08/26/so-why-isnt-perl-my-favorite-programming-language/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Launching SSHblock</title>
		<link>http://kagan.mactane.org/blog/2009/06/16/launching-sshblock/</link>
		<comments>http://kagan.mactane.org/blog/2009/06/16/launching-sshblock/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 18:59:26 +0000</pubDate>
		<dc:creator>Kai MacTane</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[my projects]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[system administration]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://kai.mactane.org/blog/?p=71</guid>
		<description><![CDATA[My latest software project is now available&#8230; where &#8220;latest&#8221; means &#8220;the latest thing I&#8217;ve launched, even if I actually wrote it over a year ago.&#8221; The story is simple: I was tired of seeing &#8220;failed password&#8221; messages from sshd cluttering up my logs. I was also annoyed at the constant flow of dictionary attacks, even [...]]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://kai.mactane.org/software/sshblock/">latest software project is now available</a>&#8230; where &#8220;latest&#8221; means &#8220;the latest thing I&#8217;ve <em>launched</em>, even if I actually wrote it over a year ago.&#8221;</p>
<p>The story is simple: I was tired of seeing &#8220;failed password&#8221; messages from sshd cluttering up my logs. I was also annoyed at the constant flow of dictionary attacks, even if I knew they&#8217;d never get in. So I whipped up a quick Perl script that acted as some glue between <a href="http://swatch.sourceforge.net/">Swatch</a> and iptables, and which would also give me some amount of reporting and history on who and what it was blocking.</p>
<p>Then I posted about it in my online journal, and a friend said it sounded useful. So I started getting it ready for release as a package that anyone could use&#8230;</p>
<p>And promptly realized that doing a decent, professional job of it would take more time than I had available. Fast-forward to now, when I&#8217;m unemployed and can only spend so many hours per day job-hunting&nbsp;&mdash; the result is that the world gets more software!</p>
]]></content:encoded>
			<wfw:commentRss>http://kagan.mactane.org/blog/2009/06/16/launching-sshblock/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>On Complexity Versus Efficiency</title>
		<link>http://kagan.mactane.org/blog/2009/05/02/on-complexity-versus-efficiency/</link>
		<comments>http://kagan.mactane.org/blog/2009/05/02/on-complexity-versus-efficiency/#comments</comments>
		<pubDate>Sun, 03 May 2009 01:39:04 +0000</pubDate>
		<dc:creator>Kai MacTane</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[Big O notation]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[teaching]]></category>

		<guid isPermaLink="false">http://kai.mactane.org/blog/2009/05/02/on-complexity-versus-efficiency/</guid>
		<description><![CDATA[I sometimes imagine how I would teach certain concepts, if I were put in charge of a class. (Not just in programming, either; many people who know me have said I&#8217;d make a great teacher; perhaps I&#8217;ve taken it to heart.) One of the concepts in programming that I feel has a particularly poor &#8220;ease-of-teaching [...]]]></description>
			<content:encoded><![CDATA[<p>I sometimes imagine how I would teach certain concepts, if I were put in charge of a class. (Not just in programming, either; many people who know me have said I&#8217;d make a great teacher; perhaps I&#8217;ve taken it to heart.) One of the concepts in programming that I feel has a particularly poor &#8220;ease-of-teaching versus importance-of-knowing&#8221; ratio is <em>algorithmic complexity</em>, best described using <a href="http://en.wikipedia.org/wiki/Big_O_notation">Big&nbsp;O Notation</a>.</p>
<p>I just came across a great example of one use of Big&nbsp;O Notation, in examining the trade-off between conciseness and efficiency in Perl functions to find the smallest member of an array. While looking around for a good <a href="http://www.merriampark.com/ldperl.htm">Levenshtein algorithm implementation</a>, I noticed this helper function:</p>
<pre># minimal element of a list
#
sub min
{
    my @list = @{$_[0]};
    my $min = $list[0];

    foreach my $i (@list)
    {
        $min = $i if ($i < $min);
    }

    return $min;
}</pre>
<p>And I thought, "Hmmm, that's a little odd. Why go through that entire loop, when you could just do:"</p>
<pre>sub min {
	my @list = @{$_[0]};
	return (sort @list)[0];
}</pre>
<p>Of course, hard on its heels came the thought: "Wait a second... how do those stack up in Big&nbsp;O?"</p>
<p>Without even bothering to look at the source code, I'll assume Perl's <code>sort()</code> is an implementation of <a href="http://en.wikipedia.org/wiki/Quicksort">Quicksort</a>, and will achieve O(n&nbsp;log&nbsp;n) performance on most sane data. But the <code>min()</code> function supplied at Merriam Park is O(n); for any situation where log n is greater than 1, the n&nbsp;log&nbsp;n function will take longer than the just-plain&nbsp;n algorithm.</p>
<p>This would make a <em>wonderful</em> "teachable moment": point out to the class that my function is shorter, and easier to read and understand, but the other one is <em>more efficient</em>. This is exactly the sort of thing that Big&nbsp;O Notation is useful for, and it's something that can't be easily expressed just by looking at the code itself.</p>
<p>(Not that I'd try to tell the class that one way or the other was <em>automatically</em> better. The real usefulness of this example is the way the psychological complexity and the computational efficiency are in opposition to each other. It makes a great springboard to talk about how we decide on what trade-offs to make in engineering.)</p>
]]></content:encoded>
			<wfw:commentRss>http://kagan.mactane.org/blog/2009/05/02/on-complexity-versus-efficiency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

