<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Modern Perl Books, a Modern Perl Blog</title>
    <link rel="alternate" type="text/html" href="http://www.modernperlbooks.com/mt/" />
    <link rel="self" type="application/atom+xml" href="http://www.modernperlbooks.com/mt/atom.xml" />
    <id>tag:www.modernperlbooks.com,2009-01-23:/mt//1</id>
    <updated>2010-07-26T18:22:27Z</updated>
    <subtitle>Modern Perl programming, circa 2010, relies on the collected wisdom of the entire Perl ecosystem.  It&apos;s time to write elegant, reliable, maintainable, well-tested, and predictable code.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.23-en</generator>

<entry>
    <title>A Checklist for Writing Maintainable Perl</title>
    <link rel="alternate" type="text/html" href="http://www.modernperlbooks.com/mt/2010/07/a-checklist-for-writing-maintainable-perl.html" />
    <id>tag:www.modernperlbooks.com,2010:/mt//1.211</id>

    <published>2010-07-26T16:53:01Z</published>
    <updated>2010-07-26T18:22:27Z</updated>

    <summary>Suppose you want to write a program in Perl. (Suppose you have written a program in Perl.) If the thesis behind what I call Modern Perl is correct, you can write that program well or you can write that program...</summary>
    <author>
        <name>chromatic</name>
        <uri>http://www.wgz.org/~chromatic</uri>
    </author>
    
    <category term="advocacy" label="advocacy" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="maintainability" label="maintainability" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modernperl" label="modern perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl5" label="perl 5" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="programming" label="programming" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modernperlbooks.com/mt/">
        <![CDATA[<p>Suppose you want to write a program in Perl.  (Suppose you <em>have written</em> a program in Perl.)  If the thesis behind what I call Modern Perl is correct, you can write that program well or you can write that program poorly.  (For supporting arguments for that thesis, see Piers Cawley's <a href="http://www.bofh.org.uk/2010/07/25/a-tale-of-two-languages">A tale of two languages</a>.)</p>

<p>Likely you've seen examples of Poorly Written Perl on the Internet.  They serve as the YouTube comments to Nabokov of English language.  In other words, the proper response to a reluctant admission that:</p>

<blockquote>Yes, I know that Perl <em>can</em> be written in an object-oriented and readable way.</blockquote>

<p>&mdash; Tim Bray, <a href="http://www.tbray.org/ongoing/When/201x/2010/07/21/DPH">D.P.H.</a></p>

<p>... or that:</p>

<blockquote>There's also been a push in some applications to rewrite Perl utilities in Bash to enhance portability between platforms. While Perl exists on just about every platform out there, there are vagaries that can cause issues with differing Perl versions, which then leads to portability problems.</blockquote>

<p>&mdash; Paul Venezia, <a href="http://www.infoworld.com/t/languages-and-standards/whatever-happened-perl-012">Is it still libelous if you end your titles with question marks?</a>

<p>... the proper response is "Why <em>didn't</em> you write your code with maintainability in mind?"</p>

<p>I know, I know.  That's not helpful.  Here's a quick checklist to help those of you writing Perl (or those of you trying to hire people to write Perl (or those of you trying to hire people to learn to write Perl)) to determine if you're capable of writing Perl well:</p>

<ul>

<li>Do you know how to use <a href="http://perldoc.perl.org/">the Perl documentation</a></li>

<li>Do you use <a href="http://www.cpan.org/">CPAN</a> modules?</li>

<li>Do you use the <a href="http://search.cpan.org/perldoc?Module::Starter">CPAN distribution layout</a> for organizing your code?</li>

<li>Have you enabled <a href="http://search.cpan.org/perldoc?strict">strict</a>users and <a href="http://search.cpan.org/perldoc?warnings">warnings</a>?  Is the resulting code clean of warnings and errors?</li>

<li>Are you using the standard <a href="http://search.cpan.org/perldoc?Test::Tutorial">Perl testing framework</a>?  (Did you write tests at all?)</li>

<li>Do you have an <a href="http://search.cpan.org/perldoc?Module::Build">automated Perl configuration, build, dependency resolution, installation, and distribution mechanism</a>?</li>

<li>Does your code conform to local <a href="http://search.cpan.org/perldoc?Perl::Tidy">Perl layout guidelines</a>?</li>

<li>Does your code conform to <a href="http://search.cpan.org/perldoc?Perl::Critic">Perl community standards for maintainability and correctness</a>?</li>

<li>Are you familiar with the local <a href="http://www.pm.org/">Perl mongers group</a>?</li>

<li>Are you using a recent version of Perl?</li>

<li>Are you familiar with <a href="http://perldoc.perl.org/perlsec.html">writing secure Perl</a>?</li>

<li>Do you use source control?</li>

<li>Do you use functions?</li>

<li>Do you use modules?</li>

<li>Do you use objects?</li>

<li>Do you use <a href="http://moose.perl.org/">Moose</a> or another abstraction mechanism from the CPAN?</li>

<li>Do you <a href="http://perldoc.perl.org/perlpod.html">document your Perl code</a>?</li>

<li>Do you use language constructs you don't understand, copied and pasted from elsewhere, smushed together into a hateful melange of barely-working confusion you occasionally tweak just to see what happens, and one afternoon you get sick of it and call it done?</li>

</ul>

<p>You don't have to answer all of those questions in the correct way to write good and maintainable Perl, but if you answer most of those questions in the wrong way, <em>of course you'll write bad code</em>.</p>

<p>Perl allows people to accomplish their tasks without having to learn much, without having to participate in strange and unfamiliar ceremonies, and without even being much good at programming at all.  That's by design, and that's a good thing for very specific circumstances.  Yet if you approach programming as if it were merely typing and retyping until something barely working fell out of your typewriter, you're going to make lots of messes, and no language can save you from an unprofessional lack of discipline.</p>

<p>Writing good code requires discipline in any language.</p>
]]>
        
    </content>
</entry>

<entry>
    <title>The Best Art Continues to Surprise</title>
    <link rel="alternate" type="text/html" href="http://www.modernperlbooks.com/mt/2010/07/the-best-art-continues-to-surprise.html" />
    <id>tag:www.modernperlbooks.com,2010:/mt//1.210</id>

    <published>2010-07-22T22:10:03Z</published>
    <updated>2010-07-22T22:32:02Z</updated>

    <summary>I attended an exhibit about the work of Leonardo da Vinci several months ago. Part of that exhibit was a thorough analysis of his Mona Lisa painting. &quot;It&apos;s perhaps the most famous painting in the world,&quot; I thought. &quot;I&apos;ve seen...</summary>
    <author>
        <name>chromatic</name>
        <uri>http://www.wgz.org/~chromatic</uri>
    </author>
    
    <category term="art" label="art" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="languagedesign" label="language design" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modernperl" label="modern perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl5" label="perl 5" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modernperlbooks.com/mt/">
        <![CDATA[<p>I attended an exhibit about the work of Leonardo da Vinci several months
ago.  Part of that exhibit was a thorough analysis of his Mona Lisa painting.
"It's perhaps the most famous painting in the world," I thought.  "I've seen it
(or at least replicas) thousands of times before."</p>

<p>Then at the suggestion of the exhibit, I looked behind the model and saw more details, such as a low wall, the lack of eyebrows and eyelashes, and other small details that have always been there but somehow failed to catch my attention.</p>

<p>Several years ago, I read an analysis of Roger Zelazny's The Chronicles of Amber series.  The analyst admitted that he re-read the series every few years and learned new things each time.  (Zelazny's Chandleresque tone in the first five books contributes to the depth of the books, but so does the fact that his characters gladly lie to, backstab, betray, confuse, manipulate, and distrust each other and their own selves.)  A reinterpretation of a single line which seemed so innocent during the last reading could cause you to see a character in an entirely different light.</p>

<p>Good art is like that.</p>

<p>Today I understood an underused feature of Perl 5 better.</p>

<p><a href="http://search.cpan.org/~pscust/">Paulo Custodio</a> filed a bug on the Modern Perl draft that the explanation of module unimporting was incomplete.  I had written that:</p>

<pre><code>no Module::Name qw( arguments );</code></pre>

<p>... is equivalent to:</p>

<pre><code>BEGIN { Module::Name-&gt;unimport( qw( arguments ) ) }</code></pre>

<p>In all accuracy (and, upon reflection, obviousness), <code>no Module::Name qw( arguments )</code> is equivalent to:</p>

<pre><code>BEGIN
{
    require 'Module::Name';
    Module::Name-&gt;unimport( qw( arguments ) );
}</code></pre>

<p>Even though I rarely use module unimporting and have never, to my best
recollection, unimported a module I haven't previously <code>use</code>d, its
obvious that unimporting through <code>no</code> should imply
<code>require</code>.  (I have trouble imagining an interface where you'd initially load a pragma with <code>no</code>, unless you use <a href="http://www.modernperlbooks.com/.../a-stupid-experiment-in-reliability-and-maintainability.html">strictperl</a>, but clever people can do clever things.)</p>

<p>You may all now chuckle at how long it took me to realize this (and, yes, I did read the Perl 5 source code to prove to myself that this occurs).</p>
]]>
        
    </content>
</entry>

<entry>
    <title>Eliminating Errors with Little Languages</title>
    <link rel="alternate" type="text/html" href="http://www.modernperlbooks.com/mt/2010/07/eliminating-errors-with-little-languages.html" />
    <id>tag:www.modernperlbooks.com,2010:/mt//1.209</id>

    <published>2010-07-20T17:51:01Z</published>
    <updated>2010-07-20T19:48:47Z</updated>

    <summary>Jamie McCarthy made an interesting point about type safety in embedded SQL on String-Plus: SQL is a great example for this. Relational databases are more useful with strong typing, so EMPLOYEE_ID is incompatible with PRODUCT_ID even if they are both...</summary>
    <author>
        <name>chromatic</name>
        <uri>http://www.wgz.org/~chromatic</uri>
    </author>
    
    <category term="apis" label="APIs" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="languagedesign" label="language design" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modernperl" label="modern perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl6" label="perl 6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modernperlbooks.com/mt/">
        <![CDATA[<p><a
href="http://www.modernperlbooks.com/mt/2010/07/string-plus.html#comment-500">Jamie
McCarthy made an interesting point about type safety in embedded SQL</a> on <a
href="http://www.modernperlbooks.com/mt/2010/07/string-plus.html">String-Plus</a>:</p>

<blockquote>SQL is a great example for this. Relational databases are more
useful with strong typing, so EMPLOYEE_ID is incompatible with PRODUCT_ID even
if they are both implemented as INT. It'd be a great idea to see those
constraints implemented at the perl level, presumably by giving perl more
knowledge of the database schema than even the database engine
has.</blockquote>

<p>Imagine that you have, or can write, a little language parser for a SQL-like language.  My simple example was:</p>

<pre><code>SQL {{
    UPDATE users SET address = { Address $address } WHERE user = { User $user }
}}</code></pre>

<p>This can decompose into several operations:</p>

<ul>

<li>Get the value of the <code>$address</code> variable.</li>

<li>Get the primary key of the <code>$user</code> variable.</li>

<li>Prepare a database query with a rewritten query string which uses placeholders for the <code>$address</code> and <code>$user</code> variables to avoid SQL injection and other interpolation errors.</li>

<li>Execute the query.</li>

</ul>

<p>That's a nice interface, but you can do better.  As I suggested, you can add error checking if you know the structure of the database:</p>

<ul>

<li><em>Get the metadata which describes the <code>users</code> table.</em></li>

<li><em>Verify that the required fields (<code>address</code> and <code>user</code> exist).</em></li>

<li>Get the value of the <code>$address</code> variable.</li>

<li>Get the primary key of the <code>$user</code> variable.</li>

<li>Prepare a database query with a rewritten query string which uses placeholders for the <code>$address</code> and <code>$user</code> variables to avoid SQL injection and other interpolation errors.</li>

<li>Execute the query.</li>

</ul>

<p>You can take advantage of type checking too:</p>

<ul>

<li>Get the metadata which describes the <code>users</code> table.</li>

<li>Verify that the required fields (<code>address</code> and <code>user</code> exist).</li>

<li><em>Verify that the type of <code>$address</code> is compatible with the type of the <code>address</code> field.  Repeat for <code>$user</code> and <code>user</code>.</em></li>

<li>Get the value of the <code>$address</code> variable.</li>

<li>Get the primary key of the <code>$user</code> variable.</li>

<li>Prepare a database query with a rewritten query string which uses placeholders for the <code>$address</code> and <code>$user</code> variables to avoid SQL injection and other interpolation errors.</li>

<li>Execute the query.</li>

</ul>

<p>If you know the structure of the database when the program starts, you can start to push some of this type checking to the point of compilation.  (You may not be able to perform <em>all</em> of the type checking at compilation time, but you can do as much as possible as early as possible to prevent as many errors as possible.)</p>

<p>That's simple and easy.  Now imagine something more interesting:</p>

<pre><code>SQL {{
    SELECT name, address FROM users, addresses GIVEN { User $user }
}}</code></pre>

<p>It's obvious from the syntax of the query language that the database needs to perform a join operation, and it's obvious that the primary key of the <code>$user</code> object is the important key of the operation.  If the program knows the relationship of the <code>users</code> and <code>addresses</code> tables, it can join them effectively as well.</p>

<p>Don't get caught up in the syntax or the semantics of the remainder of examples here; they exist to demonstrate possibilities, not the final form of battle-tested code.  Even so, imagine a dynamic query:</p>

<pre><code>SQL {{
    SELECT @fields FROM { Table $table_one }, {Table $table_two } }
}}</code></pre>

<p>Again the structure and intent of the code is obvious.  The operations are now:</p>

<ul>

<li>Find the primary keys for <code>$table_one</code> and <code>$table_two</code>.</li>

<li>Verify that they're joinable.</li>

<li>Verify that all members of <code>@fields</code> are present in either <code>$table_one</code> or <code>$table_two</code>.</li>

<li>Construct the query.</li>

</ul>

<p>If I were to implement this, I'd make a <code>join_tables</code> multimethod.  It takes two arguments (generalizable to more, but follow along with two for now).  Imagine that it looks something like this:</p>

<pre><code>multi join_tables( Table $t1, Table $t2 ) { ... }

multi join_tables( Any, Any ) { fail() }</code></pre>

<p>Given two <code>Table</code> arguments, the first multi candidate matches and gets called.  Given any other combination of arguments, the second candidate matches and produces an error.</p>

<p>Knowing that you have two <code>Table</code> objects isn't enough, however.  The tables might have no relationship to each other.  Imagine if you somehow <em>could</em> verify that the tables have an appropriate relationship.  If I were to implement this, I might check that the keys of the tables matched types, perhaps with a syntax something like:</p>

<pre><code>multi join_tables ( Table $t1, Table $t2 where { $t1.primary_key eqv $t2.foreign_key( $t1 ) } ) { ... }</code></pre>

<p>That is, the keys must be of equivalent types.  If one key is a
<code>user_id</code> and the other is an <code>Integer</code>, the where clause
won't match for this candidate, so a different multi will get called.</p>

<p>Now imagine that for those embedded SQL minilanguage statements where table name is available at compilation time and sufficient type information exists to verify the statements themselves at compilation time:</p>

<pre><code>SQL {{
    SELECT name, address FROM { User users }, { Address addresses }
}}</code></pre>

<p>... then everyone who uses this minilanguage (and has set up the table information appropriately) gets safety and correctness by default.  Some of that can even occur <em>before the program runs</em>.  The rest of it can occur as the program runs.</p>

<p>(A really, really good type checker and optimization system could infer that some errors are impossible even if it can't prove the use of a single type in every case.)</p>

<p>Now imagine that you have a language which allows you to build minilanguages like this, to build APIs which specify correct operations and fall back to good error reporting on incorrect operations, and which do so without interfering with other code and other extensions.</p>

<p>Welcome to Perl 6.</p>]]>
        
    </content>
</entry>

<entry>
    <title>String-Plus</title>
    <link rel="alternate" type="text/html" href="http://www.modernperlbooks.com/mt/2010/07/string-plus.html" />
    <id>tag:www.modernperlbooks.com,2010:/mt//1.208</id>

    <published>2010-07-16T17:59:43Z</published>
    <updated>2010-07-16T20:17:01Z</updated>

    <summary>What does this variable represent? my $thingie = It&apos;s obviously an address, but what does Perl know about it? Perl knows it&apos;s a string. Perl knows it&apos;s some 60 characters long. Perl may even know that it&apos;s a valid string...</summary>
    <author>
        <name>chromatic</name>
        <uri>http://www.wgz.org/~chromatic</uri>
    </author>
    
    <category term="apis" label="APIs" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="languagedesign" label="language design" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modernperl" label="modern perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl5" label="perl 5" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl6" label="perl 6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modernperlbooks.com/mt/">
        <![CDATA[<p>What does this variable represent?</p>

<pre><code>my $thingie =<<'END';
Thaddeus Droit
4616 NW Washington Place
Beaverton, OR 97006
END</code></pre>

<p>It's <em>obviously</em> an address, but what does Perl know about it?  Perl knows it's a string.  Perl knows it's some 60 characters long.  Perl may even know that it's a valid string of Latin-1 characters.</p>

<p>Perl doesn't know where the string came from, nor that it contains a street
address or a legal name nor a zip code (and not a zip + 4).  Any meaning to the
program beyond "It's a string of some 60 characters and is valid in the Latin-1
encoding" is far beyond what Perl knows about it.  That's why the name of the
variable is <code>$thingie</code>; even though Perl doesn't care about variable
names, calling it <code>$address</code> instead could have led you to believe
there's more structural meaning to this chunk of memory than actually
exists.</p>

<p>Names are important, at least to people maintaining source code.  This code is obviously wrong:</p>

<pre><code>$user-&gt;set_address( $birthday );</code></pre>

<p>... but to Perl it might as well be:</p>

<pre><code>$foo-&gt;bar( $baz );</code></pre>

<p>... for all of the semantic meaning it understands.  There's no obvious
intent.</p>

<p>I know you're smart and you're way ahead of me and you think "If I wanted a
good static type system, I know where to find Haskell or OCaml and I'd never
let code that bad get out of code review and why aren't you writing tests." but
that's not the point.  You can be super careful or <a
href="http://www.modernperlbooks.com/mt/2010/07/strings-and-security-and-designing-away-bugs.html">make
APIs which restrict the most natural way to write code in the host language in
favor of extra security</a>.  That may be the right approach.  (You have to be
careful, though: the ease of interpolating untrusted user input into a raw
string or the use of register globals in PHP seems analogous to the <a
href="http://definitions.uslegal.com/a/attractive-nuisance/">attractive
nuisance doctrine</a>, where people who don't know any better can't analyze the
risk appropriately.</p>

<p>There may be another way.</p>

<p>Suppose I annotated the address:</p>

<pre><code>my Address $thingie =<<'END';
Thaddeus Droit
4616 NW Washington Place
Beaverton, OR 97006
END</code></pre>

<p>It's still a chunk of memory with certain characteristics, but now it has an
extra piece of metadata related to the program itself (and not merely Perl
itself).  A clever compiler could detect certain places where the semantics of
an operation don't match:</p>

<pre><code>method set_address(Address $addy) { ... }</code></pre>

<p>... though you do have to be able to resolve this kind of dispatch at
compilation time to prove the type safety of the entire program at compilation
time.  (I've seen suggestions that even Smalltalk programs can resolve some
85-90% of dispatch targets in a static fashion.)</p>

<p>You don't have to go that far; runtime verification with a good test suite
is effectve, can be fairly cheap, and is available right now in Perl 5 with <a
href="http://moose.perl.org/">Moose</a>.</p>

<p>There's still another way.  Consider again the untrusted input example.  If
you enable tainting, you might read user input into an address:</p>

<pre><code>my Address $untrusted_addy = $req-&gt;get( 'address' );</code></pre>

<p>You don't see it in the declaration, but the "This is tainted!" metadata is present in <code>$untrusted_addy</code>.  How do you deal with that?</p>

<p>You could be picky about always untainting untrusted data, but can you do
that accurately and effectively?  Can you rely on everyone always getting it
right?</p>

<p>What if you could write:</p>

<pre><code>SQL {{
    UPDATE users SET address = { Address $address } WHERE user = { User $user }
}}</code></pre>

<p>... and Perl could verify that <code>$address</code> is an appropriate
Address (and <code>$user</code> is an appropriate User), could quote and escape and validate both of
them effectively, could extract the primary key from <code>$user</code>, and
could untaint any tainted <code>$address</code> or <code>$user</code>?</p>

<p>If your language supports multiple dispatch, lets you define your own types,
lets you override stringification, and can override interpolation for cases
like these, you can do such things.</p>

<p>In other words, you could turn what would otherwise be a raw string into an
embedded little language with its own syntax and semantics, interoperate with
native data structures in the host language, and provide composable
safety&mdash;and users don't have to know much of anything about how this
works, as it pretty much does what they expect.</p>

<p>I can imagine a language like that.</p>
]]>
        
    </content>
</entry>

<entry>
    <title>Strings and Security and Designing Away Bugs</title>
    <link rel="alternate" type="text/html" href="http://www.modernperlbooks.com/mt/2010/07/strings-and-security-and-designing-away-bugs.html" />
    <id>tag:www.modernperlbooks.com,2010:/mt//1.207</id>

    <published>2010-07-14T16:23:45Z</published>
    <updated>2010-07-14T17:43:15Z</updated>

    <summary>Some people believe that security problems and other severe bugs are inevitable. Some of these people believe that conscientious design and clear thinking about how languages and APIs work is irrelevant; bad code is possible in every language. Bad code...</summary>
    <author>
        <name>chromatic</name>
        <uri>http://www.wgz.org/~chromatic</uri>
    </author>
    
    <category term="apis" label="APIs" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="languagedesign" label="language design" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modernperl" label="modern perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perlprogramming" label="perl programming" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="security" label="security" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modernperlbooks.com/mt/">
        <![CDATA[<p>Some people believe that security problems and other severe bugs are inevitable.  Some of these people believe that conscientious design and clear thinking about how languages and APIs work is irrelevant; bad code is possible in every language.</p>

<p>Bad code <em>is</em> possible in any language and wrong code is possible with any API.  Even so, it's possible to create languages and APIs which make the right thing so much easier than the wrong thing that only the most incompetent (or dangerously malicious) write bad code.</p>

<p>Imagine, for example, a database access layer which forbids the use of raw strings to create SQL queries.  You might have to write:</p>

<pre><code>my $sth = $dbh->select( @tables )->join( %relations )->where( %conditions );</code></pre>

<p>That's not necessarily a <em>beautiful</em> interface dashed off after a moment of thinking, but it has an important security property: it avoids the interpolation of untrusted user input.  All data sent to the database may go through a quoting or untainting process without the user having to remember to do so.</p>

<p>A similar library could help avoid malicious user input from interfering
with the display or operation of a web site, for example.  These are both
specific cases of a general principle: <a
href="http://www.modernperlbooks.com/mt/2010/07/dont-parse-that-string.html">replace
unstructured string data with structured data</a>.  In both cases, the
structure of the data makes the intent of the data clear, which allows the
library to ensure as much safety as possible.</p>

<p>This principle has other implications as well; more on that next time.</p>
]]>
        
    </content>
</entry>

</feed>
