<?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; learningperl</title>
	<atom:link href="http://perlblogs.com/category/learningperl/feed/" rel="self" type="application/rss+xml" />
	<link>http://perlblogs.com</link>
	<description>Posts from selected Perl bloggers</description>
	<lastBuildDate>Fri, 18 May 2012 19:03:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>When Sugar and Semantics Collide</title>
		<link>http://www.modernperlbooks.com/mt/2010/07/when-sugar-and-semantics-collide.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/07/when-sugar-and-semantics-collide.html#comments</comments>
		<pubDate>Thu, 01 Jul 2010 18:10:12 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[languagedesign]]></category>
		<category><![CDATA[learningperl]]></category>
		<category><![CDATA[modernperl]]></category>
		<category><![CDATA[moose]]></category>
		<category><![CDATA[perl5]]></category>
		<category><![CDATA[perlprogramming]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I use Moose to explain object orientation in Perl in the Modern Perl book. It's much easier to explain the what and why of OO with syntax like: { package Cat; use Moose; has 'name', is =&#38;gt; 'ro', isa =&#38;gt;...]]></description>
			<content:encoded><![CDATA[
        <p>I use <a href="http://moose.perl.org/">Moose</a> to explain object orientation in Perl in the <a href="http://www.modernperlbooks.com/mt/2010/06/modern-perl-the-book-the-draft.html">Modern Perl book</a>.  It's much easier to explain the what and why of OO with syntax like:</p>

<pre><code>{
    package Cat;

    use Moose;

    has 'name', is =&gt; 'ro', isa =&gt; 'Str';
    has 'age',  is =&gt; 'ro', isa =&gt; 'Int';
    has 'diet', is =&gt; 'rw';
}</code></pre>

<p>... than the corresponding code where you must write your own accessors, poke into a blessed hash directly (and <code>bless</code> it yourself), perform your own coercions and verifications, and the like.</p>

<p>Of course, the preferred syntax for doing this within the Moose documentation is different from how I've done things.  Moose recommends:</p>

<pre><code>{
    package Cat;

    use Moose;

    has 'name' =&gt; <strong>(</strong>is =&gt; 'ro', isa =&gt; 'Str'<strong>)</strong>;
    has 'age' =&gt;  <strong>(</strong>is =&gt; 'ro', isa =&gt; 'Int'<strong>)</strong>;
    has 'diet' =&gt; <strong>(</strong>is =&gt; 'rw'<strong>)</strong>;
}</code></pre>

<p>Sometimes you quote the name of the attribute and sometimes you don't.</p>

<p>Should I drop the parentheses?  Should I drop the fat arrow between the name of the attribute and its specializers?  I do in my own Moose code for my preferences, and I did in the book.  Then I thought about it and realized <em>why</em> I write code this way.</p>

<p>First, a digression.  <a href="http://www.modernperlbooks.com/mt/2010/06/the-virtuous-dilemma-of-iterative-improvements.html#comment-439">Perrin Harkins mentioned the inability of the "Takes a block!" prototype to replicate builtin syntaxes</a> as a reason to dislike syntax-bending modules such as <a href="http://search.cpan.org/perldoc?Error">Error</a>.  For example:</p>

<pre><code>
use Error ':try';

try
{
    ...
}
catch
{
    ...
}<strong>;</strong></code></pre>

<p>... <em>really</em> needs that trailing semicolon.  For similar reasons,
many modules which use <a
href="http://search.cpan.org/perldoc?Devel::Declare">Devel::Declare</a> magic
go through contortions to add trailing commas and semicolons.  Perl 5's syntax
is malleable, but when the parser wants something from the lexer, it really
really wants something from the lexer.  (When it wants to know that a statement
or a group of terms has ended, you don't get to lie.)</p>

<p>In other words, even though you have a lot of options for mangling Perl 5's
syntax any way you like it, the semantics of the host language will shine
through.  A parenthesis is a parenthesis.  A labeled block is a labeled block.
A bare <code>sub { ... }</code> is never an expression on its own, and it can
never terminate an outer expression.</p>

<p>This is one of the downfalls of the so-called "embedded domain specific
languages".  If you haven't written your own parser, you'll have to take what
you can get.  This is even true if you <em>do</em> write a parser and generate
and <code>eval</code> code, and it's especially true if your EDSL desugars to
chained function or method calls.</p>

<p>I'm not suggesting a flaw with Moose's approach: it's clever and Perlish and
doesn't succumb to the saccharine cutery of so many other so-called DSLs.  (To
my knowledge, no one in the Moose world has claimed it's anything other than
Perl 5 syntax bent slightly into something which looks declarative enough.)</p>

<p>My concern&mdash;especially when explaining object orientation in Perl 5 to
novices&mdash;is that any extra syntactic elements might confuse people to
think that they mean more than they mean.  You and I might both understand that
the grouping parentheses in the <code>Cat</code> attribute declaration are
merely visual hints to the reader that the specializers are subordinate to the
attribute itself and that the fat arrow between the name of the attribute and
its grouped specializers confers the notion of pairing between the attribute
and its specializers, but how do you explain that to someone who's still
struggling to figure out what this encapsulation thing is all about?</p>

<p>I've attempted caution throughout the book such that the fat comma always signifies a pairish relationship, such as for hash keys or named arguments.  Certainly you can always use it in place of the skinny comma (and, barring any quoting changes, vice versa), but is it <em>clear</em> to do so?</p>

<p>Likewise, you can wrap parentheses around almost any old rvalue (barring precedence changes) and not change the behavior of lists, yet this confuses novices all the time:</p>

<pre><code>my @lololol = ( 1, 2, ( 3, 4, (5, 6) ) );</code></pre>

<p>I'm not criticizing the Moose documentation or the standard approaches to formatting Moose code.  I'm not suggesting a change.  I don't like deviating from community standards for declaring Moose attributes.  Even so, avoiding the need to explain the equivalencies of syntax to people for whom learning syntax is still a really big deal is itself to me a big deal.</p>
        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/07/01/when-sugar-and-semantics-collide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New to Programming or New to Perl</title>
		<link>http://www.modernperlbooks.com/mt/2010/05/new-to-programming-or-new-to-perl.html</link>
		<comments>http://www.modernperlbooks.com/mt/2010/05/new-to-programming-or-new-to-perl.html#comments</comments>
		<pubDate>Fri, 07 May 2010 21:12:28 +0000</pubDate>
		<dc:creator>chromatic</dc:creator>
				<category><![CDATA[learningperl]]></category>
		<category><![CDATA[modernperl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl5]]></category>
		<category><![CDATA[perlprogramming]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Warning, philosophy ahead! I alluded to this question when I asked should the Modern Perl book prefer cpanminus?. I've tried to explain my goal a couple of times in private, but I've never done so systematically, and I've never invited...]]></description>
			<content:encoded><![CDATA[
        <p>Warning, philosophy ahead!</p>

<p>I alluded to this question when I asked <a href="http://www.modernperlbooks.com/mt/2010/04/should-novices-prefer-cpanminus.html">should the Modern Perl book prefer cpanminus?</a>.  I've tried to explain my goal a couple of times in private, but I've never done so systematically, and I've never invited wide discussion.</p>

<p>I'm trying to figure out the right audience for the <a href="http://github.com/chromatic/modern_perl/">Modern Perl book</a> in preparation for publishing this summer.  My initial idea to write the book came from two places.</p>

<p>First, the Camel book is a decade old, and there'll never be a new edition which covers Perl 5.  Despite the fact that fourteen (almost fifteen) stable releases of Perl 5 have come out since then (and at least four of them, possibly five) count as major, the canonical printed language reference is out of date and, at this point, all but abandoned.</p>

<p>Second, the best explanation of JavaScript I've ever encountered is <a href="http://google-code-updates.blogspot.com/2009/03/doug-crockford-javascript-good-parts.html">JavaScript: The Good Parts</a>.  Like almost any other language, JavaScript has some good ideas, some poor implementations of good ideas, and some bizarre ideas that you shouldn't ever use.  In 176 pages, Crockford explains how the language works and how its pieces fit together.  Without covering everything, you can go from knowing how to dabble with it to writing good code.</p>

<p>Yet you're not an expert.  You understand enough of the theoretical underpinnings of the language and the practical issues of using it to be productive, to use it to its advantages, and how to avoid or at least work around misfeatures.</p>

<p>I want to do something similar for Perl 5.  I believe that <a href="http://www.modernperlbooks.com/mt/2010/04/from-novice-to-adept-perldoc.html">understanding how to use perldoc is essential to programming Perl well</a>, as is understanding the two forms of context and how they influence other code, as is understanding Perl's operator-oriented container-based type system.</p>

<p>I believe it's possible to explain how Perl 5 works in a couple of hundred pages, such that someone who's worked through a tutorial or two on setting up a Perl development environment and written something more than "Hello, world!" can <em>understand</em> Perl and continue to learn and to become productive.  If you add in <a href="http://www.modernperlbooks.com/mt/2010/04/test-driven-learning.html">permission to experiment with small snippets of code</a>, there are few limits as to where readers can go.</p>

<p>In short, I want to produce a book you can hand to someone who says "Perl?  Oh, I've played around with it a bit." and tell them "Once you've read and understood this, you'll understand Perl."</p>

<p>I <em>think</em> I can do that without also bearing the burden of teaching people how to program in general.  I <em>assume</em> that pointing interested novices to tutorials to set up Strawberry Perl and/or Padre is sufficient explanation for the basic material.</p>

<p>What do you think?</p>
        
    ]]></content:encoded>
			<wfw:commentRss>http://perlblogs.com/2010/05/07/new-to-programming-or-new-to-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

