<?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>/dev/psychology &#187; Language</title>
	<atom:link href="http://p.einarsen.no/category/language/feed/" rel="self" type="application/rss+xml" />
	<link>http://p.einarsen.no</link>
	<description></description>
	<lastBuildDate>Sun, 30 Oct 2011 11:29:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Accelerate your Perl learning 2: From novice to adept</title>
		<link>http://p.einarsen.no/accelerate-your-perl-learning-2-from-novice-to-adept/</link>
		<comments>http://p.einarsen.no/accelerate-your-perl-learning-2-from-novice-to-adept/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 08:40:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Expert knowledge]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=324</guid>
		<description><![CDATA[I stated in an article some time back that a challenge in learning is that the knowledge setting experts apart from novices isn&#8217;t explicitly known by either &#8211; it&#8217;s tacit knowledge. Since that was about learning Perl, I just want to bring attention to this good series of blog posts by chromatic under the header [...]]]></description>
			<content:encoded><![CDATA[<p>I stated in <a href="http://p.einarsen.no/accelerate-your-perl-learning/" target="_blank">an article some time back that a challenge in learning</a> is that the knowledge setting experts apart from novices isn&#8217;t explicitly known by either &#8211; it&#8217;s <em><a href="http://en.wikipedia.org/wiki/Tacit_knowledge" target="_blank">tacit knowledge</a></em>. Since that was about learning Perl, I just want to bring attention to this good series of blog posts by <a href="http://www.modernperlbooks.com/mt/" target="_blank">chromatic</a> under the header &#8220;From Novice To Adept&#8221;, as they fill in a bit of this gap:</p>
<ul>
<li></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-the-risk-of-being-undone.html" target="_blank">The Risk of Being Undone</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-the-risk-of-maintenance.html" target="_blank">The Risk of Maintenance</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-the-risk-of-failure.html" target="_blank">The Risk of Failure</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-pronouns-in-perl.html" target="_blank">Pronouns in Perl</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-functional-versus-structural-code.html" target="_blank">Functional versus Structural Code</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-the-act-of-naming.html" target="_blank">The Act of Naming</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/11/from-novice-to-adept-the-act-of-naming.html" target="_blank">On Answers to Smart Questions</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-embrace-the-copious-documentation.html" target="_blank">Embrace the Copious Documentation</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-embracing-idioms.html" target="_blank">Embracing Idioms</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-cleaning-up-bad-code.html" target="_blank">Cleaning Up Bad Code</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-declarations-and-scope.html" target="_blank">Declarations and Scope</a></li>
<li><a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-scalar-context-and-arrays.html" target="_blank">Scalar Context and Arrays</a><a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-cleaning-up-bad-code.html" target="_blank"><br />
</a></li>
</ul>
<p>And a bonus: <a href="http://www.modernperlbooks.com/mt/2010/01/essential-skills-for-perl-5-programmers.html" target="_blank">Essential Skills For Perl 5 Programmers.</a></p>
<p>Are there any other good resources out there expicitly aiming at taking novices to the next level &#8211; or is that just when general &#8220;documentation&#8221; takes over as learning instruments? What&#8217;s it like in other languages?</p>
<p>Also, while updating with Perl news, scruffy old perl.org has become <a href="http://www.perl.org/" target="_blank">dashing new perl.org</a>!</p>
<p><em>Updated with new articles March 8, 2010</em><em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/accelerate-your-perl-learning-2-from-novice-to-adept/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Great Perl Comeback?</title>
		<link>http://p.einarsen.no/the-great-perl-comeback/</link>
		<comments>http://p.einarsen.no/the-great-perl-comeback/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 20:50:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=315</guid>
		<description><![CDATA[Google Timeline is a wonderful tool! Here is a Google Timeline for the search &#8220;Perl&#8221; showing an exceptionally interesting trend: It may seem like the recent efforts to market Perl, as well as the Perl Ironman blogging drive, is paying off big time in terms of online attention! The graph certainly sends a clear message [...]]]></description>
			<content:encoded><![CDATA[<p>Google Timeline is a wonderful tool! Here is <a href="http://www.google.com/search?q=perl&amp;hl=en&amp;client=safari&amp;rls=en&amp;tbo=1&amp;tbs=tl:1,tll:2000,tlh:2019&amp;ei=bpHwStijEsXI-QaLqLjrBw&amp;sa=X&amp;oi=timeline_histogram_main&amp;ct=timeline-histogram&amp;cd=11&amp;ved=0CBMQyQEoCw" target="_blank">a Google Timeline for the search &#8220;Perl&#8221;</a> showing an exceptionally interesting trend:</p>
<p><a href="http://www.google.com/search?q=perl&amp;hl=en&amp;client=safari&amp;rls=en&amp;tbo=1&amp;tbs=tl:1,tll:2000,tlh:2019&amp;ei=bpHwStijEsXI-QaLqLjrBw&amp;sa=X&amp;oi=timeline_histogram_main&amp;ct=timeline-histogram&amp;cd=11&amp;ved=0CBMQyQEoCw" target="_blank"><img title="Skjermbilde 2009-11-03 kl. 20.48.47" src="http://p.einarsen.no/wp-content/uploads/2009/11/Skjermbilde-2009-11-03-kl.-20.48.47.png" alt="The great Perl comeback?" width="492" height="127" /></a></p>
<p>It may seem like the <a href="http://perlhacks.com/2009/07/marketing-perl.php" target="_blank">recent</a> <a href="http://use.perl.org/~Ovid/journal/39353" target="_blank">efforts</a> to <a href="http://szabgab.com/blog/2009/07/1248529850.html" target="_blank">market Perl</a>, as well as <a href="http://ironman.enlightenedperl.org/" target="_blank">the Perl Ironman blogging drive</a>, is paying off big time in terms of online attention!  The graph certainly sends a clear message that Perl is alive and kicking as never before.</p>
<p>Note: I tried to create comparative graphs for Ruby, Python and Java, but was left with enough noise from fake gems, snake attacks and earthquakes to fill several Hollywood movies. Any suggestions for good searches for comparison are welcome.</p>
<p>Note 2: Maybe this is just caused by some Google indexing algorithm gone bad, but a quick visual inspection of the first 100 hits indicated that the August and September hits are real Perl mentions.  Is this a real empirical indication that the recent efforts are really paying off?</p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/the-great-perl-comeback/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Functional programming and disappearing variable roles</title>
		<link>http://p.einarsen.no/functional-programming-and-disappearing-variable-roles/</link>
		<comments>http://p.einarsen.no/functional-programming-and-disappearing-variable-roles/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 19:25:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=212</guid>
		<description><![CDATA[After writing about variable roles a while back, I&#8217;ve been thinking a lot about the way I use variables. The post also got quite a lot of attention, so it seems to have hit a note with people. And no wonder it does: the concept kinda promises to tell you something profound about programming. The [...]]]></description>
			<content:encoded><![CDATA[<p>After writing about <a href="http://p.einarsen.no/variables-and-the-roles-they-play/">variable roles a while back</a>, I&#8217;ve been thinking a lot about the way I use variables. The post also got quite a lot of attention, so it seems to have hit a note with people. And no wonder it does: the concept kinda promises to tell you something profound about programming. The problem is that it doesn&#8217;t really deliver on the promise.</p>
<p>The first observation anyone with some experience in programming will see, is that the majority of the roles are loop control variables (check the post, but basically they mention &#8220;stepper&#8221;, &#8220;most-recent-holder&#8221;, &#8220;most-wanted-holder&#8221;, &#8220;gatherer&#8221; and &#8220;follower&#8221; as distinct roles, as well as &#8220;fixed-value&#8221; and &#8220;temporary&#8221;, who also could be said to be typical loop control roles. </p>
<p>My first idea was that if all these are necessary to traverse loops, perhaps a historized scalar variable would be helpful. I.e. the &#8220;follower&#8221; could just be a ->prev() method, there could be a sum of the history and so on. And it turns out there is a variable history module: <a href="http://search.cpan.org/dist/Tie-History/">Tie::History</a> (just remember to turn on AutoCommit).</p>
<p>Now maybe that wasn&#8217;t such a great idea. Or maybe it just isn&#8217;t thought properly through. Because what happens then is that you just start doing list operations on the history. Hence, maybe the list operations are just the way to go, and a more functional programming style will get rid off the elaborate loop control variables. Or so I suggested in the post. </p>
<p>Here, I&#8217;m trying out some attempts at bypassing the loop control variable roles by using a more <a href="http://en.wikipedia.org/wiki/Declarative_programming">declarative/functional programming style</a>. I&#8217;ve made some examples of typical imperative style loops, and have tried to see I could get rid of the traditional variable roles by doing it in a declarative style.  Have a look and see if it seems meaningful.</p>
<p>(Also, it gives me an opportunity to try out the awesome <a href="http://kpumuk.info/projects/wordpress-plugins/codecolorer/">CodeColorer</a> code viewer).</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> USA China Netherlands<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Norway Finland Sweden <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$longest</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;"># $most wanted holder;</span><br />
<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$country</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@countries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;"># most recent holder</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$longest</span> &nbsp;<span style="color: #339933;">&lt;</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$country</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$longest</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$country</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Longest name: $longest<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></div>
<p>In my alternative take, I realized I ended up with both sort of a &#8220;most-wanted-holder&#8221; and TWO temporary variables. However, that I want to store my value somewhere, I can&#8217;t help, and at least there are no iterations using it. The temporary variables are worse, however. The point was to get rid of them after all.</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> USA China Netherlands<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Norway Finland Sweden <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$longest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/sort.html"><span style="color: #000066;">sort</span></a> <span style="color: #009900;">&#123;</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$b</span> <span style="color: #339933;">&lt;=&gt;</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$a</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@countries</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Longest name: $longest<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></div>
<p>This version looks a bit sleeker, but sorting could be slower than a single iteration. Another approach that should have the same profile as the intial loop is <a href="http://search.cpan.org/~gbarr/Scalar-List-Utils-1.21/lib/List/Util.pm#reduce">reduce</a> from the core module <a href="http://search.cpan.org/~gbarr/Scalar-List-Utils-1.21/lib/List/Util.pm">List::Util</a>:</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">use</span> List<span style="color: #339933;">::</span><span style="color: #006600;">Util</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span>reduce<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> USA China Netherlands<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Norway Finland Sweden <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$longest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> reduce <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$b</span> <span style="color: #339933;">&gt;</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">$b</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">$a</span> <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">@countries</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Longest name: $longest<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></div>
<p>And now we have even more internal variables in use..</p>
<p>Ok, the &#8220;stepper&#8221; role should be easier to remove. Here is a simple loop with a &#8220;stepper&#8221; and a &#8220;gatherer&#8221;:</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> China Netherlands Norway<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USA Finland Sweden <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># stepper</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@uppercased</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># gatherer</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">@countries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$i</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/uc.html"><span style="color: #000066;">uc</span></a> <span style="color: #0000ff;">$countries</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">eq</span> <span style="color: #0000ff;">$countries</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@uppercased</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$countries</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Uppercase names: @uppercased<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></div>
<p>It breaks my heart to write code like this. But it is also typical imperative code! This one lends itself easier to list operations too:</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> China Netherlands Norway<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USA Finland Sweden <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@uppercased</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/grep.html"><span style="color: #000066;">grep</span></a> <span style="color: #009900;">&#123;</span> <a href="http://perldoc.perl.org/functions/uc.html"><span style="color: #000066;">uc</span></a> <span style="color: #0000ff;">$_</span> <span style="color: #b1b100;">eq</span> <span style="color: #0000ff;">$_</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@countries</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Uppercase names: @uppercased<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></div>
<p>One construct I vividly recognize is the &#8220;follower&#8221;, described as &#8220;A data item that gets its new value always from the old value of some other data item&#8221;. I am probably not the only one having written code balancing a pair of previous/this type variables. Here is a slightly contrived example that reports every adjacent pair of the same length:</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> USA China Netherlands<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Norway Sweden France Finland <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$previous_country</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;"># Follower</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@pairs</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Gatherer</span><br />
<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$country</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@countries</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;"># most recent holder</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$country</span> <span style="color: #339933;">==</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$previous_country</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@pairs</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$previous_country</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$country</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$previous_country</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$country</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Got pairs @pairs&quot;</span><span style="color: #339933;">;</span></div></div>
<p>This did not turn out as easy as I expected. If you try to do functional operations in Perl using core libraries, <em>reduce</em> is basically the only method that let you operate on list items in a non-independent fashion. And the only way I found to do this with reduce is even more contrived than my imperative example:</p>
<div class="codecolorer-container perl blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">use</span> List<span style="color: #339933;">::</span><span style="color: #006600;">Util</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> reduce <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@countries</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span> USA China Netherlands<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Norway Sweden France Finland <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@pairs</span><span style="color: #339933;">;</span><br />
reduce <span style="color: #009900;">&#123;</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$a</span> <span style="color: #339933;">==</span> <a href="http://perldoc.perl.org/functions/length.html"><span style="color: #000066;">length</span></a> <span style="color: #0000ff;">$b</span> <span style="color: #b1b100;">and</span> <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@pairs</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$a</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$b</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">$b</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@countries</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Got pairs @pairs&quot;</span><span style="color: #339933;">;</span></div></div>
<p>Now, except from the last example, I find the declarative approach to be generally far more easy to read. While that could just be because they are shorter, I don&#8217;t think that is sufficient as an explanation for that &#8211; there is plenty of compact code that would be easier to understand if it was more explicitly stated. </p>
<p>Now, cognitive psychology actually has an explanation of why declarative list operations like this are easier to understand.  And I&#8217;ll present the evidence for that in my next post. </p>
<p>Until then, there is <a href="http://www.joelonsoftware.com/items/2006/08/01.html">an article about functional programming on Joel on Software</a> that is worth reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/functional-programming-and-disappearing-variable-roles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cognition, computers and electric currents</title>
		<link>http://p.einarsen.no/cogntition-computers-and-electric-currents/</link>
		<comments>http://p.einarsen.no/cogntition-computers-and-electric-currents/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 12:31:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Understanding Code]]></category>
		<category><![CDATA[action potentials]]></category>
		<category><![CDATA[cogntion]]></category>
		<category><![CDATA[physiology]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=207</guid>
		<description><![CDATA[This is just a quick quote from the course description of a ten year old course in Cognitive Psychology and Computer Programming at the Texas A&#38;M: Computer programming perhaps more than any other manufacturing endeavor begins with a thought and through skilled application of knowledge yields an intrinsically proven object that is itself almost mental [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick quote from the course description of a ten year old <a href="http://www.rtis.com/nat/user/jfullerton/school/psyc345/program.htm" target="_blank">course in Cognitive Psychology and Computer Programming</a> at the Texas A&amp;M:</p>
<blockquote><p>Computer programming perhaps more than any other manufacturing endeavor begins with a thought and through skilled application of knowledge yields an intrinsically proven object that is itself almost mental (encoded electrical information).</p></blockquote>
<p>It&#8217;s a good argument for why cognitive psychology is relevant for computer programming, but even more important, it points out the almost mental nature of computer programs.</p>
<p>Physiologically, the way our brains operate is mainly through bursts of electrical current called <a href="http://en.wikipedia.org/wiki/Action_potential" target="_blank">Action Potentials</a>, that propagate information down neurons in a on-off fashion. Some people will call it binary, but the information conveyed is typically frequencies rather than binary patterns  (But this is a somewhat contentious question).</p>
<p>Here&#8217;s a beautiful drawing of neural communication from Wikipedia:</p>
<p><a href="http://en.wikipedia.org/wiki/Action_potential" target="_blank"><img class="alignnone" title="Neuron" src="http://upload.wikimedia.org/wikipedia/commons/3/3e/Neurons_big1.jpg" alt="" width="510" height="539" /></a></p>
<p>So you have a mental construction in a human brain contained in electrical signals, and this is transferred over to a construction of electrical signals in a computer.  Add that you usually want these two representations to be identical, you have a good argument why programming language design should be based strongly on cognitive science!</p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/cogntition-computers-and-electric-currents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is readability, or simple != readable</title>
		<link>http://p.einarsen.no/what-is-readability-or-simple-readable/</link>
		<comments>http://p.einarsen.no/what-is-readability-or-simple-readable/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 20:07:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Understanding Code]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[readability]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=161</guid>
		<description><![CDATA[As a programmer, you write for two very different kinds of readers. One is the rigid computer platform, the other is the human maintainers of your code. For the former we have quite conclusive guidelines on what works, but the latter is only consistent as a source of disagreement and uncertainty. Typically the guideline is [...]]]></description>
			<content:encoded><![CDATA[<p>As a programmer, you write for two very different kinds of readers. One is the rigid computer platform, the other is the human maintainers of your code. For the former we have quite conclusive guidelines on what works, but the latter is only consistent as a source of disagreement and uncertainty. Typically the guideline is &#8220;<em><a href="http://c2.com/cgi/wiki?CodeForTheMaintainer">Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.</a></em>&#8220;, while most people end up writing as if the person maintaining the code is themselves.</p>
<p>Neither approach is particularly good -I can&#8217;t imagine code written for violent psychopaths  would really be that great to maintain. And on the other end, a lot of coders optimize for their own readability, and will argue the finer points of formatting from that point of view, not that of <em>the actual readers</em> &#8211; missing the point that readability is ultimately decided by the reader, not the writer.</p>
<p>I certainly catch myself doing this quite often.</p>
<p>In the Perl world, this is probably an even bigger issue than in other languages.  <a href="http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it">There-Is-More-Than-One-Way-To-Do-It</a> is still one of Perls big strenghts, but certainly not all the ways are equally good &#8211; which is why <a href="http://oreilly.com/catalog/9780596001735/">Perl Best Practices</a> is now a staple of any Perl-wielding office. The contrasting Python, with it&#8217;s <a href="http://www.python.org/dev/peps/pep-0020/">&#8220;there should be one — and preferably only one — obvious way to do it&#8221;</a>, seems to be able to get away with 19 simple statements to define the pythonic best practice.</p>
<p>Now, anyone can have an opinion, particularly since research on code readability it still quite lacking. We just don&#8217;t know for certain yet what makes people get code. However, cognitive psychologists have been interested for several decades in how people generally organize large data structures in their brains, and some of this has given some neat practical applications for coding, such as <a href="http://www.si.umich.edu/furnas/Papers/FisheyeCHI86.pdf">Furnas&#8217; paper on &#8216;Fish-eye&#8217; views (1986)</a>. (This is basically about IDEs with collapsing code branches, but now you know why that&#8217;s nice, how to do it right and who thought of it first.)</p>
<p>Research on general language comprehension, however, is a massive field. In the <a href="http://www.acm.org/jcdl/jcdl01/">ACM Journal of Computer Documentation</a>&#8216;s August 2000 issue, <a href="http://portal.acm.org/citation.cfm?id=344599.344630">George R. Klare provides some clear-minded and research-based adviced for communicators </a>that might be enlightening and is a good starting point for thinking about readability of normal text &#8211; that might apply to programming.</p>
<p>He specifies four purposes of readability:</p>
<ul>
<li>Reading speed and efficiency.</li>
<li>Reader judgment.</li>
<li>Readership.</li>
<li>Comprehension, Learning and Retention.</li>
</ul>
<p>Of these, only the last is of any big interest for programmers; you don&#8217;t typically care about the speed the maintainer needs to read your code. You might care about the Reader  judgment if you code to impress your fellow programmers, but that is another chapter. Readership applies to how the size of the readership may be a function of  the simplicity of the text &#8211; a consideration on the skill level of your maintainers, perhaps, but few people code with the intention of their code to be read by a large audience.</p>
<p>However, the biggest issue with text and code is comprehension. Even more so in programming code, as it is essential that the maintainer is able to create a <em>precise</em> representation of the code in his own mind. Also he must be able to understand both what it actually does and what the intention is, since these don&#8217;t always add up.  For debugging purposes, it is actually completely essential that the reader can separate the soft human intentions from the hard computer operations, so any code must be understood on two levels simultaneously.</p>
<p>Now, how does readability affect comprehension? First, keep in mind that readability in natural language usually refers to choice of words and sentence length, and is typically measured by level of education necessary to read the text. This might not be appropriate for code readability &#8211; level of programming skill might not map to level of code understanding in the same way, and readability in code is often just a matter of indentation and syntactics.</p>
<p>But it probably maps somewhat close. This is where research is lacking again, so it is hard to tell.</p>
<p>Klare&#8217;s big advice, however, is that higher readability does not always convert into higher comprehension, but is modulated by situation and traits in the readers. And that is the important part. He describes four conditions when it does not work as you would think:</p>
<ol>
<li>A reader can understand at higher levels than expected if his motivation is high. Also, skill level is a fuzzy concept.</li>
<li>If time is not limited, increase in readability might not make a difference on comprehension. The more time is limited, the larger the effect of readability</li>
<li>The greater the readers background knowledge on the topic, the less effect does readability have. On the other hand, even an expert on one field may prefer higher levels of readability in texts outside his field.</li>
<li>Type and level of motivation might affect comprehension.</li>
</ol>
<p>or to quote his summary:</p>
<blockquote><p>[..] more readable, written material is likely to produce greater comprehension, learning and retention than less readable only when one or more of the following factors are present: the less readable is much harder than the more readable, and clearly beyond the reader&#8217;s usual level; reading time is limited; the reader does not have a large amount of background or experience with the topic being covered; and, the reader has a relatively strong set to learn.</p></blockquote>
<p>Now does this particulary increase understanding of readability of programming code?</p>
<p>Perhaps not.</p>
<p>However, if we think of readability not as just the reading of code as natural language, but rather of understanding of the semantic concepts, there is an interesting observation to be made.  If we consider using more basic programming to make the program easier to understand, while avoiding more advanced concepts, Klare&#8217;s summary of readability shows something that also adds up with other research, namely that <em>this approach to readability doesn&#8217;t always increase comprehension.</em></p>
<p>In a very recent piece of research using Scala, <a href="http://infoscience.epfl.ch/record/138586?of=HD">Gilles Dubouchet found that using more compact and advanced functional programming methods rather than basic, typical loop-constructs increased comprehension</a>.  Although one single piece of research such as Dubouchet&#8217;s is too limited to base decisions on, it becomes more interesting when it actually adds up with prior research on language comprehension.</p>
<p><strong>Together it indicates that using more advanced methodology can increase comprehension for both original programmers and maintainers, unless they are pressed on time or motivation.</strong></p>
<p>Unlike many other languages, Perl allows you to increase the complexity of your programming across methodology quite freely. You can start with the simple baby-Perl, go through procedural programming, add objects or start playing with functional approaches. You can use <a href="http://search.cpan.org/~adamk/Aspect-0.21/lib/Aspect.pm">Aspect Oriented Programming</a> or add on your own crazy, homespun programming methodology, if you so please.  For <em>comprehension and readability purposes</em>, the above research indicates that if you consider your audience and their situation well, going for a higher and more advanced level might not be a disadvantage.</p>
<p>But do keep in mind that the research is still a bit patchy, and this is mostly an argument without empirical data. But I&#8217;ll make sure I report what I find, as this is just the first in many articles about readability&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/what-is-readability-or-simple-readable/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Never mind the language, the programmer is what matters</title>
		<link>http://p.einarsen.no/never-mind-the-language-the-programmer-is-what-matters/</link>
		<comments>http://p.einarsen.no/never-mind-the-language-the-programmer-is-what-matters/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 20:31:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=151</guid>
		<description><![CDATA[Another piece of old research. It&#8217;s so interesting, though, I can&#8217;t help putting a note up about it. In a piece of research released in 2000, Lutz Prechelt compared C, C++, Java, Perl, Python, Rexx, and Tcl.  (It&#8217;s gotten a fair bit of attention before, so it&#8217;s not new material) What&#8217;s so good is the [...]]]></description>
			<content:encoded><![CDATA[<p>Another piece of old research. It&#8217;s so interesting, though, I can&#8217;t help putting a note up about it. In a piece of research released in 2000, <a href="http://page.mi.fu-berlin.de/prechelt/Biblio/jccpprt_computer2000.pdf">Lutz Prechelt compared C, C++, Java, Perl, Python, Rexx, and Tcl</a>.  (It&#8217;s gotten a fair bit of <a href="http://www.codinghorror.com/blog/archives/000365.html">attention</a> <a href="http://stackoverflow.com/questions/354124/are-there-statistical-studies-that-indicates-that-python-is-more-productive">before</a>, so it&#8217;s not new material)</p>
<p>What&#8217;s so good is the fairly rigorous and natural approach &#8211; instead of leaning exclusively on local students or one company&#8217;s employees performing some unnatural task, the researchers solicited for solutions online for the scripting languages (Perl, Python, Rexx and Tcl) and got 80 different implementations of a simple dictionary task. With these tasks they ran a lot of metrics and generated solid, comparable empirical data. Read it for the details (there is also <a href="http://www.cis.udel.edu/~silber/470STUFF/article.pdf" target="_blank">a prettified version available</a>).</p>
<p>I liked this observation, however:</p>
<blockquote><p>For all program aspects investigated, the performance variability due to different programmers (as described by the bad/good ratios) is on average about as large or even larger than the variability due to different languages.</p></blockquote>
<p>It&#8217;s quite profound &#8211; and even if the study itself is a bit dated and has some minor flaws &#8211; this observation probably still holds regardless!</p>
<p>Also, for Perl programmers, this statistic is quite neat:</p>
<p><img class="alignnone" title="Perl Graph execution speed" src="http://www.einarsen.no/perl-graph-speed.png" alt="" width="396" height="363" /></p>
<p>The variability in execution speed for Perl programs were far lower than for the other languages except Tcl. It might be over-interpreting, but it indicates Perl is a bit more predictable &#8211; or Perl programmers are &#8211; than most of the other languages. Also, speed-wise is holding up quite good, and even the higher end of the range of execution speed is better than the higher end for all other languages.</p>
<p><em>The curious thing is that this indicates that the variability between programmers matters less with Perl (and Tcl) than the other languages. </em>Or at least speed-wise, but the low variability also seems to be a tendency in the other metrics in the paper.</p>
<p>What&#8217;s so interesting, though, is how this demonstrates in hard numbers the importance of human variables in programming. It&#8217;s almost like framework matters less than the people using it.. funny, eh?</p>
<p>Also see <a href="http://wiki.python.org/moin/LanguageComparisons" target="_blank">this page of language comparison links.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/never-mind-the-language-the-programmer-is-what-matters/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Variables and the roles they play</title>
		<link>http://p.einarsen.no/variables-and-the-roles-they-play/</link>
		<comments>http://p.einarsen.no/variables-and-the-roles-they-play/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 20:52:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Understanding Code]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Variable roles]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=109</guid>
		<description><![CDATA[I promised to explain better the idea of variable roles I mentioned in the previous post about natural programming. This is based on a finding by Finnish researcher Jorma Sajaniemi (published work), who discovered that 99% of variables in novice&#8217;s code can be categorized in to 11 different roles. These roles are variable uses every [...]]]></description>
			<content:encoded><![CDATA[<p>I promised to explain better the idea of variable roles I mentioned in the previous <a href="http://p.einarsen.no/?p=86" target="_blank">post about natural programming</a>.</p>
<p>This is based on a finding by Finnish researcher Jorma Sajaniemi (<a href="http://en.scientificcommons.org/jorma_sajaniemi" target="_blank">published work</a>), who discovered that 99% of <a href="http://www.cs.joensuu.fi/~saja/var_roles/index.html" target="_blank">variables in novice&#8217;s code can be categorized in to 11 different </a><em><a href="http://www.cs.joensuu.fi/~saja/var_roles/index.html" target="_blank">roles</a>. </em>These roles are variable uses every programmer will recognize: iterators, constants, flags and so on &#8211; although in role-terminology the names somewhat differ (<em>steppers</em>, <em>fixed-values</em> and <em>one-way flags</em>, for example).  Mr. Sajaniemi has also found that these <a href="http://www.ppig.org/papers/17th-sajaniemi.pdf" target="_blank">roles matches <em>tacit </em>knowledge in expert programmers</a> &#8211; i.e. the 11 roles are also typically intuitively recognized by expert programmers even if it is not explicit or active knowledge.</p>
<p>Whether or not the same 11 variable roles are enough to categorize expert variable use seems harder to pin down, but there is a <a href="http://www.cs.joensuu.fi/~saja/var_roles/abstracts/08_Heikkila_MasterThesis.html" target="_blank">master&#8217;s thesis from their lab finding that they are sufficient</a>. And, not surprisingly, in expert-written programs, the roles have a significantly different distribution. Judge for yourself, is this enough to describe your own variables?</p>
<table class="inline" border="0" cellpadding="3">
<tbody>
<tr>
<th>Role</th>
<th>Example</th>
<th>Informal definition</th>
</tr>
<tr>
<td>Fixed value</td>
<td><tt>maxStringLength</tt></td>
<td>A data item that does not get a new proper value after its initialization</td>
</tr>
<tr>
<td>Stepper</td>
<td><tt>count</tt></td>
<td>A data item stepping through a systematic, predictable succession of values</td>
</tr>
<tr>
<td>Most-recent holder</td>
<td><tt>inputData</tt></td>
<td>A data item holding the latest value encountered in going through a succession of unpredictable values, or simply the latest value obtained as input</td>
</tr>
<tr>
<td>Most-wanted holder</td>
<td><tt>maximum</tt></td>
<td>A data item holding the best or otherwise most appropriate value encountered so far</td>
</tr>
<tr>
<td>Gatherer</td>
<td><tt>sum</tt></td>
<td>A data item accumulating the effect of individual values</td>
</tr>
<tr>
<td>Follower</td>
<td><tt>prev</tt></td>
<td>A data item that gets its new value always from the old value of some other data item</td>
</tr>
<tr>
<td>One-way flag</td>
<td><tt>errorsOccurred</tt></td>
<td>A two-valued data item that cannot get its initial value once the value has been changed</td>
</tr>
<tr>
<td>Temporary</td>
<td><tt>temp</tt></td>
<td>A data item holding some value for a very short time only</td>
</tr>
<tr>
<td>Organizer</td>
<td><tt>sortArray</tt></td>
<td>A data structure storing elements that can be rearranged</td>
</tr>
<tr>
<td>Container</td>
<td><tt>processQueue</tt></td>
<td>A data structure storing elements that can be added and removed</td>
</tr>
<tr>
<td>Walker</td>
<td><tt>currNode</tt></td>
<td>A data item traversing in a data structure</td>
</tr>
</tbody>
</table>
<p>The list is from <a href="http://www.cs.joensuu.fi/~saja/var_roles/role_intro.html" target="_blank">An introduction to the role of variables</a>, but there is also <a href="http://www.cs.joensuu.fi/~saja/var_roles/role_list.html" target="_blank">a more extensive description</a> available.</p>
<p>Sajaniemi&#8217;s aim with the research and role concept appears to be teaching programming. For Perl-programmers, it can be interesting to see an article about <a href="http://jite.org/documents/Vol6/JITEv6p199-214Nikula269.pdf" target="_blank">Teaching Python using Roles</a>, which might tell on how interesting it is for teaching Perl. Otherwise, his research in variable roles seems to revolve around a Java world.</p>
<p>What I find most exciting with this is the approach to studying and extending programming. Instead of going the computer science route, it looks at how people program, identifies interesting patterns and <strong>puts forward numbers and testable hypotheses. </strong></p>
<p><strong> </strong>Now can this be used to actually extend programming and help expert programmers?</p>
<p>My first observation is that at least five of the variables seem to all play parts in very typical loop patterns, namely <em>stepper, most-recent-holder, most-wanted-holder, gatherer </em>and<em> follower. </em>If this is such a typical way of organizing code, perhaps language design can help this &#8211; or perhaps it already does in the immutable states and for-comprehensions of functional languages such as<a href="http://en.wikipedia.org/wiki/Scala_%28programming_language%29" target="_blank"> Scala</a>, or the <a href="http://perldoc.perl.org/functions/map.html" target="_blank">map</a>, g<a href="http://perldoc.perl.org/functions/grep.html" target="_blank">rep</a> and <a href="http://hop.perl.plover.com/" target="_blank">higher-order functions in Perl</a>. Or if nothing else it may explain why expert programmers often tend more towards those constructs (or ?).</p>
<p>But if we know these are the typical ways variables are used, how about implementing variable roles (instead of types) with special functionality that simplifies and enhances what they are used for: <em>most-wanted-holders</em> that triggers events, <em>gatherers</em> and <em>followers</em> with history, <em>walkers</em> with an implicit track, <em>organizers</em> and <em>containers</em> optimized for moving elements or not and so on.</p>
<p>But if that is a good idea is hard to tell. At least in Perl, some things can be patched on with a little magical module, so it would be simple to test. I&#8217;m playing around with it, and I&#8217;ll keep you updated if something meaningful comes out of it. If you know of any other language that implements something similar, <em>please</em> leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/variables-and-the-roles-they-play/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>An alternative vision for the Perl Eco-System</title>
		<link>http://p.einarsen.no/an-alternative-vision-for-the-perl-eco-system/</link>
		<comments>http://p.einarsen.no/an-alternative-vision-for-the-perl-eco-system/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 17:16:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Perl 6]]></category>
		<category><![CDATA[visions]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=101</guid>
		<description><![CDATA[I just touched upon how natural programming can be a way forward for Perl in my previous post, and quickly saw a twitter from chromatic not understanding the &#8220;criticism (?)&#8221; of Perl 6. As he is a member of the Perl 6 development team, I am happy that he noticed my post, but not so [...]]]></description>
			<content:encoded><![CDATA[<p>I just touched upon how natural programming can be a way forward for Perl in my previous post, and quickly saw a <a href="http://identi.ca/notice/9569912" target="_blank">twitter</a> from <a href="http://www.modernperlbooks.com/mt/" target="_blank">chromatic</a> not understanding the <em>&#8220;criticism (?)&#8221; </em>of Perl 6. As he is a member of the Perl 6 development team, I am happy that he noticed my post, but not so happy about the lack of understanding. So a clarification is probably called for.</p>
<p>My post was not a criticism of Perl 6. I am quite skeptical and apprehensive about P6, which shone through in my article, but criticising a project that started in 2000 for not implementing ideas published in 2008 would be rather unfair. However, Perl seems to be in search of a purpose nowadays, with <a href="http://use.perl.org/~Ovid/journal/39344" target="_blank">lessening interest</a> and corresponding <a href="http://szabgab.com/blog/2009/07/1248529850.html">calls for better marketing</a>.  I wanted to present a large challenge to programming in general, and to show that this is an opportunity for Perl and the Perl community.</p>
<p>Particularly since I don&#8217;t think better marketing is such a good idea. I think a programming ecosystem<em> </em>that makes you go <em>&#8220;wow, this is really going to make my programming great&#8221;</em> markets itself.</p>
<p>So this was actually more picking up the challenge presented by chromatic himself to come up with <a href="http://www.modernperlbooks.com/mt/2009/07/expressing-visions-for-perl-5.html" target="_blank">a vision for Perl</a>.</p>
<p>Now, that he didn&#8217;t <em>understand</em> that, I can&#8217;t help. But I am quite impressed by the Perl 6 development team that they actually pick up and notice the talk in the community that quick. That&#8217;s promising for the &#8220;community rewrite of Perl and the community&#8221; that Perl 6 development originally promised.</p>
<p><em>(Actually I just wanted to show a cool debugging tool but got carried away.)</em></p>
<p><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/an-alternative-vision-for-the-perl-eco-system/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A natural way of programming &#8211; the way for Perl?</title>
		<link>http://p.einarsen.no/a-natural-way-of-programming-the-way-for-perl/</link>
		<comments>http://p.einarsen.no/a-natural-way-of-programming-the-way-for-perl/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 14:20:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[Understanding Code]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Natural Language]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://p.einarsen.no/?p=86</guid>
		<description><![CDATA[When I hear people start talking about &#8220;natural&#8221; programming, easier ways of programming or making programming available to non-programmers, I get very skeptical. It makes me think of Logo and Turtle Graphics, or programming languages made to be more similar to natural language. It&#8217;s like you could make a simpler English to make it easier [...]]]></description>
			<content:encoded><![CDATA[<p>When I hear people start talking about &#8220;natural&#8221; programming, easier ways of programming or making programming available to non-programmers, I get very skeptical. It makes me think of <a href="http://en.wikipedia.org/wiki/Logo_%28programming_language%29">Logo and Turtle Graphics</a>, or programming languages made to be more <a href="http://en.wikipedia.org/wiki/Natural_language_programming" target="_blank">similar to natural language.</a> It&#8217;s like you could make a simpler English to make it easier for non-authors to write literature. So when I first read about <a href="http://www.cs.cmu.edu/~NatProg/" target="_blank">The Natural Programming Project</a>, I balked &#8211; although for no reason.</p>
<p>The researchers working on NPP certainly does approach programming with the aim of making it easier for laypeople, which seems like a turn-off. However, the output of the project is surprisingly interesting to the professional:  Lab studies scientifically testing the utility of <a href="http://perldesignpatterns.com/" target="_blank">design patterns</a> (they are not all great, it turns out), examining how time is spent during programming (35% on navigating code, 22% on reading!) and how we think during debugging (why did this happen?) &#8211; to mention some of the research from <a href="http://www.hcii.cs.cmu.edu/" target="_blank">their department at CMU</a>.</p>
<p>And then they have actually implementation advice and real software to help utilize the findings, like the Java debugging tool <a href="http://www.cs.cmu.edu/~NatProg/whyline.html" target="_blank">WhyLine</a>. You really have to see the <a href="http://www.cs.cmu.edu/~NatProg/movies/whyline-java-demo-web.mov">90 second introduction to WhyLine</a> to get the point, but to me it really opens up a whole new world of possible IDE addons intelligently interpreting your code to you.</p>
<p><a href="http://video.google.com/videoplay?docid=4084979380413345181#" target="_blank">This is a presentation from the Google Tech Talks</a> which summarizes a lot of the work they do. If you think like me on programming for novices, tolerate the first 7 minutes on making programming accessible &#8211; after that it gets good:</p>
<p><object id="VideoPlayback" style="width: 400px; height: 326px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://video.google.com/googleplayer.swf?docid=4084979380413345181&amp;hl=nb&amp;fs=true" /><param name="allowfullscreen" value="true" /><embed id="VideoPlayback" style="width: 400px; height: 326px;" type="application/x-shockwave-flash" width="100" height="100" src="http://video.google.com/googleplayer.swf?docid=4084979380413345181&amp;hl=nb&amp;fs=true" allowfullscreen="true"></embed></object></p>
<p>A final note relating this to my current programming language of choice, Perl: When Perl was first designed, it was with a lot of thought from Larry Wall on implementing natural language conventions <em>that actually makes sense</em>, like implicit variables, rather than blindly making it like English. Currently, however, few new things in this <em>humanist</em> regard has come out in the Perl world. The largest modernizing effort in Perl is the current, long-running effort to recreate Perl with <a href="http://perl6.org/" target="_blank">Perl 6</a>. This, however, is rather playing catch-up with other dynamic languages such as <a href="http://www.ruby-lang.org/en/" target="_blank">Ruby</a> and <a href="http://www.python.org/" target="_blank">Python</a> on technical merits, losing what sets Perl aside as a particularly expressive and truly useful language, namely the natural approach.</p>
<p>At the same time, thorough, scientific study of programming such as the NPP has made serious progress past the &#8220;make programming like writing English&#8221; idea that usually plague humanist and psychological studies of programming.  If Perl wanted to build on it&#8217;s strengths, it would be better reinvented by looking at this kind of approach -how can it fulfill the <a href="http://www.c2.com/cgi/wiki?LazinessImpatienceHubris" target="_blank">virtues of a programmer</a> better for experts who are also human?</p>
<p>Not surprisingly, I have some suggestions on what I would have liked to see for a modern Perl, that differs a wee bit from what is being done now:</p>
<ul>
<li>An IDE that uses an idea such as <a href="http://www.cs.cmu.edu/~NatProg/whyline-java.html" target="_blank">WhyLine</a>.</li>
<li>An IDE with better code navigation tools &#8211; watch the video to see some ideas.</li>
<li>A compiler that compiles your bytecode into human natural language (English) &#8211; that is only meant for <a href="http://p.einarsen.no/?p=62" target="_blank">assisting reading and understanding code</a>!</li>
<li>A
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">use warnings;</div></div>
<p>that warns about constructions that are difficult to understand: do you use ! with precedence that readers understand? Do you manipulate more variables in a block than human brains can keep track of? Is your indentation following your blocks? And so on.</li>
<li>Systematic testing of all the design patterns out there. Can we get quantitative data on number of bugs, development time, maintenance effort and reading time that you can expect when using a specific pattern? Then we would be able to sort out which patterns are worth using and which will be detrimental to your product &#8211; a very helpful addition to the current pattern collections and books.</li>
<li>Variables that even closer follow their semantic use &#8211; how about having specialized iterator variables, temporary variables, variables with history and more. (I see that I have to explain this idea further in a later post&#8230; Until then, have a look at the idea of <a href="http://www.cs.joensuu.fi/~saja/var_roles/role_intro.html" target="_blank">variable roles</a>)</li>
</ul>
<p>Those are some ideas of the top of my head &#8211; and not all of them of equal merit..</p>
<p>As the NPP provides statistics on, and as most programmers know by experience, most of your time does not go into writing fresh, new code. For an expert programmer, I dare suggest the act of expressing what you want the computer to do is rarely where the challenge lies in your 9 to 5 job. A programming language and environment that starts taking that seriously would be a truly modern and enlightened language &#8211; and winning support would be like shooting fish in a barrel.</p>
<p>In the Perl world, a common criticism of the Perl 6 development is that it is a solution to a non-existing problem. The above, I suggest, is the problem that is just waiting to be solved by a modern Perl.</p>
]]></content:encoded>
			<wfw:commentRss>http://p.einarsen.no/a-natural-way-of-programming-the-way-for-perl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
<enclosure url="http://www.cs.cmu.edu/~NatProg/movies/whyline-java-demo-web.mov" length="5369370" type="video/quicktime" />
		</item>
	</channel>
</rss>

