<?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>sirhc.us maxim.us &#187; Programming</title>
	<atom:link href="http://sirhc.us/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://sirhc.us</link>
	<description>the pathological prattle of a primal perl programmer</description>
	<lastBuildDate>Fri, 06 Jan 2012 05:04:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>OSCON 2010: Smalltalk-style Traits</title>
		<link>http://sirhc.us/oscon-2010-smalltalk-style-traits/</link>
		<comments>http://sirhc.us/oscon-2010-smalltalk-style-traits/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:07:07 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon2010]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[smalltalk]]></category>
		<category><![CDATA[traits]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=492</guid>
		<description><![CDATA[Curtis &#8220;Ovid&#8221; Poe (BBC) After a long break, an apple, a cup of coffee, and a beer, I&#8217;m back in the Perl track. The full title of this session is, Scratching the 40-Year Itch of Inheritance with Smalltalk-style Traits. This &#8230; <a href="http://sirhc.us/oscon-2010-smalltalk-style-traits/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em><a href="http://www.oscon.com/oscon2010/public/schedule/speaker/6639">Curtis &#8220;Ovid&#8221; Poe (BBC)</a></em></p>
<p>After a long break, an apple, a cup of coffee, and a beer, I&#8217;m back in the Perl track.</p>
<p>The full title of this session is, <a href="http://www.oscon.com/oscon2010/public/schedule/detail/12529">Scratching the 40-Year Itch of Inheritance with Smalltalk-style Traits</a>.</p>
<p>This is not a tutorial.  How to use <a href="http://en.wikipedia.org/wiki/Trait_(computer_science)">traits</a> is easy, but why to use them is a more complex discussion.</p>
<p>Inheritance is a very complex problem and an easy one to get wrong.  Then people start doing things with <a href="http://en.wikipedia.org/wiki/Multiple_inheritance">multiple inheritance</a> and, even if they&#8217;re not doing something deliberately stupid, they end up with <a href="http://en.wikipedia.org/wiki/Diamond_problem">diamond inheritance</a>.  Not only is this a problem, but it&#8217;s been a problem for a very long time&mdash;40 years, in fact.</p>
<p>Complex systems can lead to deep class hierarchies.  When hierarchies are deep, in particular with a dynamic language like Perl, it becomes difficult to determine where a method came from.  Even when its known where a method comes from, undesired behavior may be inherited.  This becomes worse when multiple inheritance is used.</p>
<p>As systems grow, the problem becomes two-fold:</p>
<ol>
<li>Class responsibility &#8211; larger classes are desired</li>
<li>Class reuse &#8211; smaller classes are desired</li>
</ol>
<p>Inheritance, by itself, cannot solve this problem.  So the solution is to<br />
decouple the sub-problems.</p>
<p>Several solutions have been tried:</p>
<ul>
<li>Interfaces</li>
<li>Delegation</li>
<li>Mixins &#8211; incredibly popular</li>
</ul>
<p>As expected by the name of this session, traits (or roles in the nomenclature of Moose) solve the problem far better than any of the above solutions.  Much of the session involved showing real-world application of roles to clean up code at the BBC.</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2010-smalltalk-style-traits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSCON 2010: New Beginnings in Perl 5</title>
		<link>http://sirhc.us/oscon-2010-new-beginnings-in-perl-5/</link>
		<comments>http://sirhc.us/oscon-2010-new-beginnings-in-perl-5/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 18:12:00 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[frustration]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon2010]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=477</guid>
		<description><![CDATA[Piers Cawley (BBC) After reviewing today&#8217;s session schedule, I quickly came to the conclusion that I will spend my entire day sitting in the room &#8220;Portland 256.&#8221; This is, apparently, where the Perl track is located. Paul Fenwick introduced Piers &#8230; <a href="http://sirhc.us/oscon-2010-new-beginnings-in-perl-5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Piers Cawley (BBC)</em></p>
<p>After reviewing today&#8217;s session schedule, I quickly came to the conclusion that I will spend my entire day sitting in the room &#8220;Portland 256.&#8221;  This is, apparently, where the Perl track is located.</p>
<p><a href="http://www.twitter.com/pjf">Paul Fenwick</a> introduced Piers in song, to the tune of <em>Gilligan&#8217;s Island</em>.</p>
<p>Piers switched from Perl to Ruby a while back and swore that he wouldn&#8217;t return to Perl until 6.  Facetiously, the reason he switched to Ruby was the handsome community associated with it and he reason he switched back to Perl was the amazingly supportive community associted with it.  He began with a point about programming style.  We think of code as describing <em>what</em> we are doing, but in reality the majority of our code actually describes <em>how</em> we are doing it.  This infrastructure code is noise.</p>
<p>More seriously, he absolutely hated unrolling the <tt>@_</tt> variable in every function.  In such a high level language like Perl, why must we pop arguments off the stack in the same manner we would in an assembly language?  This leads to long subroutines, every single one containing anti-patterns designed to implement the language infrastructure, instead of the language doing the work for us.</p>
<p><a href="http://search.cpan.org/dist/Moose/"><tt>Moose</tt></a> does a lot to improve writing classes, using a more declarative syntax.  However, even within Moose methods we need to write the infrastructure code.  The <a href="http://search.cpan.org/dist/MooseX-Declare/"><tt>MooseX::Declare</tt></a> module solves this problem, giving method syntax a more declarative style.  By moving the infrastructure code out of sight, we can better focus on <em>what</em> we are trying to do, rather than <em>how</em> we are doing it.</p>
<p>Piers proceeded to list the modules that &#8220;rock&#8221; and brought him back to Perl:</p>
<ul>
<li><a href="http://search.cpan.org/dist/Plack/"><tt>Plack</tt></a></li>
<li><a href="http://search.cpan.org/dist/Devel-NYTProf/"><tt>Devel::NYTProf</tt></a></li>
<li><a href="http://search.cpan.org/dist/Moose/"><tt>Moose</tt></a></li>
</ul>
<p>Perl&#8217;s object-orientation absolutely &#8220;sucks.&#8221;  However, this turns out to be a good thing.  It allows very clever people to create modules that extend the semantics of the language.  In a language like Ruby, which has a good object-orientation built-in, it&#8217;s essentially stuck.  If, in the future better ideas of object-orientation are developed, they can be implemented in Perl far more easily than in Ruby.  An interesting point: sometimes when the tool sucks, things are better.  People develop layers of tools that enhance and extend the original.</p>
<p>It also helps that the Perl release schedule has accelerated.</p>
<p>Piers continued with a high-level, hand-waving explanation of how <tt>MooseX::Declare</tt> works.  While not informative, it was entertaining.  Including a video of Matt Trout attempting to hypnotize the room.</p>
<p>Piers ended by thanking the Perl community and expressing how good it feels to be back into it and developing in Perl again.</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2010-new-beginnings-in-perl-5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OSCON 2008: Ultimate Perl Code Profiling</title>
		<link>http://sirhc.us/oscon-2008-ultimate-perl-code-profiling/</link>
		<comments>http://sirhc.us/oscon-2008-ultimate-perl-code-profiling/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 21:35:14 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[oscon2008]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=256</guid>
		<description><![CDATA[Lunch is over and I&#8217;m here to listen to Tim Bunce talk about Ultimate Perl Code Profiling with Devel::NYTProf. The Devel::DProf module is old and a waste of time and is broken. Stop using it. Take it out and shoot &#8230; <a href="http://sirhc.us/oscon-2008-ultimate-perl-code-profiling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lunch is over and I&#8217;m here to listen to Tim Bunce talk about <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/2960">Ultimate Perl Code Profiling</a> with <a href="http://search.cpan.org/Devel-NYTProf/">Devel::NYTProf</a>.</p>
<p>The <a href="http://serch.cpan.org/Devel-DProf/">Devel::DProf</a> module is old and a waste of time and is broken.  Stop using it.  Take it out and shoot it.</p>
<p>The first obvious distinction between profilers is CPU time versus real time.  CPU time tends to be highly granular, but doesn&#8217;t include I/O, context switching, or other kinds of blocking.  That&#8217;s where real time comes in.  It&#8217;s far more useful in the real world.</p>
<p>Tim, as with many of us, is interested in line-based profiling.  It provides a high level of granularity  The total subroutine time is not always useful, particularly in larger subroutines.</p>
<p>The NYTProf module is exremely fast, discounting the time taken by profiling overhead, making it quite a bit more useful for real world analysis.  It also allows profile times per block, and can be aggregated up to the subroutine level.  It&#8217;s a module with dual profilers: line-based and subroutine-based.</p>
<p>It gets better, every location that calls the subroutine keeps separate track of the subroutine time.  This allows us to determine where the majority of the subroutine calls are coming from.  For control flow statements, the decision expression is not taken into account when profiling the block that is executed.  This is useful if the loop control itself takes time that should be discounted.</p>
<p>And that&#8217;s it for the description.  Now we have half an hour to play with it.</p>
<p>The HTML-based reporting is inspired by <a href="http://search.cpan.org/dist/">Devel::Cover</a>&#8216;s reporting.  Reported for each file are the number of statements executed, the time spent in the source file and the line, block, and subroutine reports.  The subroutine reports include the amount of time spent within the subroutine and the amount of time spent in other called subroutines.  The coloring of each line of the report&mdash;red, orange, yellow, and green&mdash;give a relative measure of deviation from the norm.  Very impressive.</p>
<p>Even more impressive, Devel::NYTProf is capable of reporting exactly what a subroutine reference is called, even when it&#8217;s an anonymous subroutine compiled within an <code>eval</code>.  With a handy link also provided, the called code can be easily inspected.</p>
<p>In summary, Devel::NYTProf is awesome.  Use it.  I know I will.</p>
<p>Tim Bunce is even more impressive than most people think he is.  He is the only presenter I&#8217;ve seen so far who has managed to use IRC while giving his talk.  Well, he didn&#8217;t actually type on IRC, but he had Colloquy running in the background.  This particular IRC client uses Apple&#8217;s Growl feature to display notifications when you are mentioned in a channel.  After he&#8217;s opened up the session to questions, one of those notifications pops up on the projected display:</p>
<blockquote><p>
&lt;sirhc&gt; Adam Kennedy (to Tim Bunce): Why are you so awesome?
</p></blockquote>
<p>It got a laugh, and Tim seemed to take it all in stride, even joking that he was not looking very professional on his screen cast.  Important safety tip for session presenters, don&#8217;t leave your IRC client open.</p>
<p>[tags]oscon, oscon08, oscon2008, Perl, programming, profiling[/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2008-ultimate-perl-code-profiling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSCON 2008: Stick a fork() in It</title>
		<link>http://sirhc.us/oscon-2008-stick-a-fork-in-it/</link>
		<comments>http://sirhc.us/oscon-2008-stick-a-fork-in-it/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 18:45:32 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[oscon2008]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=251</guid>
		<description><![CDATA[First session of the day and I&#8217;m in room F150 (brought to you by Ford). The F wing, bereft of wifi. I&#8217;m here for Stick a fork() in It: Parallel and Distributed Perl with Eric Wilhelm of Scratch Computing. It&#8217;s &#8230; <a href="http://sirhc.us/oscon-2008-stick-a-fork-in-it/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>First session of the day and I&#8217;m in room F150 (brought to you by Ford).  The F wing, bereft of wifi.  I&#8217;m here for <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/2748">Stick a fork() in It: Parallel and Distributed Perl</a> with Eric Wilhelm of <a href="http://scratchcomputing.com/">Scratch Computing</a>.  It&#8217;s great to see how popular Perl still is.  It&#8217;s standing room only in here.</p>
<p>A computer once referred to a human worker who would perform calculations.  This was a fairly easy thing to cluster and &#8220;run&#8221; several computers in parallel.  As time progressed, more and faster work was desired.  Enter the electronic computer, and specifically for this talk, the Cray.  As with anything, the inner workings of the Crays of old can be recreated in Perl.  Just use the Cray module, no problem (if only it existed).</p>
<p>After the history lesson, we move into high level overviews of parallelism and pipelineing, and a note about <a href="http://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl&#8217;s Law</a>.  This was followed up with an example for detecting prime numbers by partitioning the work.</p>
<p>The slide presentation was over in under 20 minutes.  Instead, we&#8217;re jumping straight into code examples.  Awesome.</p>
<p>Or so I thought.  Unfortunately, he&#8217;s been interrupted by multiple people in the audience, who keep wanting to move off into tangential conversations.  Eric is having difficulty bringing the talk under his own control&mdash;it&#8217;s no longer his talk, but that of the somewhat rude fellow in the front row.  Neither is Eric as eloquent when he switches from a prepared talk to demonstrating and explaining real code.  It&#8217;s become far more difficult to pay attention to this session, and I find myself looking at the clock to see how much time we have until the next session.</p>
<p>For real fun, be sure to check out <a href="http://www.canspice.org/">Brad&#8217;s</a> post on Schwern&#8217;s session about <a href="http://www.canspice.org/2008/07/24/oscon-2008-skimmable-code-by-michael-schwern/">skimmable code</a>.</p>
<p>[tags]oscon, oscon08, oscon2008, Perl, programming[/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2008-stick-a-fork-in-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Ninja&#8221; Code</title>
		<link>http://sirhc.us/ninja-code/</link>
		<comments>http://sirhc.us/ninja-code/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 22:20:10 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[oscon2008]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=227</guid>
		<description><![CDATA[The Amazon booth at OSCON 2008 is advertising heavily that they are hiring. They are also holding a raffle. To enter, simple look over some Perl code they have written out on some poster board and tell them what it &#8230; <a href="http://sirhc.us/ninja-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.amazon.com/">Amazon</a> booth at OSCON 2008 is advertising heavily that they are hiring.  They are also holding a raffle.  To enter, simple look over some Perl code they have written out on some poster board and tell them what it does.  It looks a little something like this (transcribing from memory):</p>
<pre>
my $code = qq{
    print 1+1 . "\n";
    $code =~ m/(\d+)\+(\d+)/;
    $new = $1 + $2;
    $code =~ s/\d+\+(\d+)/$2+$new/;
};

for ( 1 .. 10 ) {
    eval($code);
}
</pre>
<p>What&#8217;s the first bug?  Yes, it should use <code>q{}</code>, or the variables will interpolate on the initial assignment to <code>$code</code>.  To their credit, they initially used single quotes, but people said it was too hard to read.</p>
<p>I wasn&#8217;t content with just figuring out what the code did and fixing a small bug.  I think it can be written better.</p>
<pre>
eval($code = q{
    print 1+1 . "\n";
    $code =~ s/(\d+)(\+)(\d+)/"$3$2" . ($1 + $3)/e;
    eval $code;
});
</pre>
<p>Much better.  Not only is it more concise, I was able to remove that pesky loop, so I wouldn&#8217;t be bothered by any silly upper bounds.</p>
<p>So what does it do?  Should be obvious.  Head over to the Amazon booth and let them know.</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/ninja-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OSCON 2008: Code Reviews for Fun and Profit</title>
		<link>http://sirhc.us/oscon-2008-code-reviews-for-fun-and-profit/</link>
		<comments>http://sirhc.us/oscon-2008-code-reviews-for-fun-and-profit/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 21:32:10 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[oscon2008]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=222</guid>
		<description><![CDATA[Lunch is over and I&#8217;m sitting in Code Reviews for Fun and Profit with Alex Martelli. I really wanted to go to the Perl 6 talk, but I always end up going home disappointed, because I don&#8217;t yet have Perl &#8230; <a href="http://sirhc.us/oscon-2008-code-reviews-for-fun-and-profit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lunch is over and I&#8217;m sitting in <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/2538">Code Reviews for Fun and Profit</a> with Alex Martelli.  I really wanted to go to the Perl 6 talk, but I always end up going home disappointed, because I don&#8217;t yet have Perl 6.  It&#8217;s maddening, so here I am, sitting in something that may be useful.  And we&#8217;re off.</p>
<p>Nearly everyone agrees that code reviews are a good idea, so why aren&#8217;t they done more often?  In fact, this is the very same problem we&#8217;ve had at work.  We&#8217;ve been talking about code reviews for two years, but we&#8217;ve never had one.</p>
<p>There are some barriers to entry to doing code reviews.  If revision control is not in use or automated tests aren&#8217;t being run, tackle those problems first.  Also, the need for a team process is necessary, from ticket tracking to release plans.</p>
<p>Pair programming, that tenet of XP, is a poor substitute for code reviews.  Two people working together will not magically turn one or the other into what is essentially a disinterested third party, who may catch bugs simply because they weren&#8217;t there when it was written.</p>
<p>Test-driven development is also a great way of coding, but not a substitute for reviews.  Often for the same reasons.  Tests are often just more code and the code tested is only when someone thinks to test it.</p>
<p>Even during a code review, a reverence for authority can get in the way of getting things done.  A poor, intimidated programmer may not have the courage to criticize a more senior programmer.  Instead, this can be turned around with something I use a lot myself.  I like to call it, &#8220;playing dumb.&#8221;  Instead of saying, &#8220;this won&#8217;t work,&#8221; ask what will happen for a suspicious case.</p>
<p>Socially, the only way for code reviews to work is universal buy-in.  Everyone is subjected to code reviews by everyone else.  No exceptions.  Make them a habit, a regularly-scheduled meeting.  At work, I&#8217;ve even suggested bi-weekly, or perhaps monthly, catered, lunch time code reviews.  Just to get us into the habit of doing it.</p>
<p>Code review time should not be wasted on things such as code formatting, best practices, or test coverage.  This is stupid.  These are <a href="http://search.cpan.org/dist/Devel-Cover/">objective</a> <a href="http://search.cpan.org/dist/Perl-Tidy/">tasks</a> that can be <a href="http://search.cpan.org/dist/Test-Harness/">automated</a>.</p>
<p>Instead, look for subjective things, which can&#8217;t be automatically found.  Such as code readability, algorithmic clarity, and consistent identifier naming.  Other targets for code reviews are the usual things we here over and over again as development best practices: consistent documentation that follows the internal standard, that kind of thing.</p>
<p>The remainder of the talk is essentially an enumeration of all the things to look for in code reviews.  All of them are, at least to me, common sense.  So I&#8217;m not going to spend any time writing them down.  If you don&#8217;t already know them, well go find some common sense.</p>
<p>One thing that he recommends that I like is code reviews by e-mail.  It&#8217;s an old, well-understood, and (usually) reliable tool.  So why not combine e-mail with a version control system&mdash;particularly one of the newer distributed version control systems&mdash;to perform out-of-band code reviews.  It actually sounds like a good idea to me, and I&#8217;ve done it at work a couple of times with code written by an intern.</p>
<p>What I&#8217;m starting to notice is that many of the later the recommendations for reviewing code are personal opinions of the presenter.  I think the way in which code reviews are performed are highly dependent on what works best for the group reviewing code.  It&#8217;s like so many things, from cameras to backup solutions: the best one is not the shiniest or the one with the most bells and whistles, it&#8217;s the one that&#8217;s actually used.</p>
<p>[tags]oscon, oscon08, oscon2008, programming[/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2008-code-reviews-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSCON 2008: Beautiful Concurrency with Erlang</title>
		<link>http://sirhc.us/oscon-2008-beautiful-concurrency-with-erlang/</link>
		<comments>http://sirhc.us/oscon-2008-beautiful-concurrency-with-erlang/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 19:12:55 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[oscon2008]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=219</guid>
		<description><![CDATA[My second session of the day is Beautiful Concurrency with Erlang. I&#8217;m here for two reasons. First, Erlang looks cool; second, the speaker, Kevin Scaldeferri, is a friend of mine. Erlang is a pure functional language (and thus no side-effects) &#8230; <a href="http://sirhc.us/oscon-2008-beautiful-concurrency-with-erlang/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My second session of the day is <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/3065">Beautiful Concurrency with Erlang</a>.  I&#8217;m here for two reasons.  First, <a href="http://www.erlang.org/">Erlang</a> looks cool; second, the speaker, Kevin Scaldeferri, is a friend of mine.</p>
<p>Erlang is a pure functional language (and thus no side-effects) with strong dynamic typing and syntax similar to Prolog and ML.  Most notably, it contains concurrency primitives, which is what we&#8217;re here to hear about today.</p>
<p>Erlang concurrency primitives include <code>spawn</code>, to create a process, <code>!</code>, to send a message to a process, and <code>receive</code>, to listen for a message.  These are not system level processes, but other Erlang processes.  It&#8217;s a lot like using <code>fork</code> in imperative languages, but less messy.</p>
<p>Erlang, like many functional languages, can implement quick sort in three lines of code.  I was having a discussion with a friend of mine about this topic yesterday.  It&#8217;s very nice, and demonstrates the power of functional languages to trivially solve an already solved set of problems, but is it any use in the real world?  Maybe.  While I&#8217;ve not seen any non-trivial examples, I&#8217;m reserving judgment.</p>
<p>The first example is a demonstration on how simple it is to parallelize the quick sort algorithm.  It&#8217;s not a worthwhile example, in fact, it&#8217;s a particularly bad idea, but it serves as a reasonable example of the ease of use of the concurrent features in Erlang.  So far, it seems like changing a <code>map</code> call&mdash;something I love from Perl&mdash;to <code>pmap</code>.</p>
<p>The <code>pmap</code> function is not a built in function (BIF), but a library function built on top of the built in concurrency primitives.  The code implementing the function is actually quite simple, and should be available in the slides available at the end of the conference.  Conceptually, it spawns as many processes as necessary and uses them to call the function being mapped.  It then gathers the results, waiting for each process to complete.  It&#8217;s quite similar to code I&#8217;ve written to do scientific processing using <a href="http://en.wikipedia.org/wiki/Message_Passing_Interface">MPI</a>, but I&#8217;ve always thought functionally when coding.</p>
<p>After explaining concurrency, we make the jump to distributed systems.  What&#8217;s everyone&#8217;s favorite distributed system?  <a href="http://twitter.com/">Twitter</a>!  Twitter, while not designed as such, is essentially a messaging system.  Erlang does message passing very well, and almost all programs are designed using this paradigm.  So Kevin took a stab at implementing a Twitter-like system in Erlang, the key ideas of which he will present to us.</p>
<p>The lightweight and convenient process architecture of Erlang lends itself to the problem.  Every user can be represented as a process.  Each process can then send and receive messages.  In effect, the problem&mdash;the messaging part anyway&mdash;is now solved.  But, what about scaling to multiple machines?</p>
<p>It turns out to easy (but you knew it would, right?).  All we need to do is pull in the <code>global</code> module and we can bind our users not only to a process identifier, but combine that with a given machine as well.</p>
<p>However, we still don&#8217;t have a reliable system.  If a process dies, that user is no longer in the system.  So it really is a lot like Twitter.</p>
<p>OTP, the Open Telecom Platform (a legacy name from Erlang&#8217;s history at Ericcson), provides a set of common behaviors and patterns for writing reliable and distributed system.  The programmer simply declares what interface they would like to use, then implement a set of callbacks defined for that behavior.  Reminds me a bit of <a href="http://search.cpan.org/dist/Class-Role/">roles</a> (because I have an unhealthy need to relate everything back to Perl).</p>
<p>As with everything in Erlang, it is almost impossibly easy to set up this reliability.  I still can&#8217;t get over how well the syntax maps to how I actually think about code.</p>
<p>A question was raised about how to go about setting up the necessary cluster of hosts used in Erlang&#8217;s mesh network.  Kevin went into it briefly, but it&#8217;s unfortunately out of scope for this session.</p>
<p>And, with that, it&#8217;s time for lunch.  Thanks, Kevin!</p>
<p>[tags]oscon, oscon08, oscon2008, Erlang, concurrency, programming[/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2008-beautiful-concurrency-with-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSCON 2008: Practical Erlang Programming</title>
		<link>http://sirhc.us/oscon-2008-practical-erlang-programming/</link>
		<comments>http://sirhc.us/oscon-2008-practical-erlang-programming/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 23:59:24 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=205</guid>
		<description><![CDATA[After lunch and our trip to the Apple Store, I&#8217;m sitting in Portland 256 for the Practical Erlang Programming. It&#8217;s being taught by Francesco Cesarini of Erlang Training and Consulting Ltd. Over 90 people registered for this tutorial, and the &#8230; <a href="http://sirhc.us/oscon-2008-practical-erlang-programming/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After lunch and our <a href="http://sirhc.us/journal/2008/07/22/belly-up-to-the-bar-were-geniuses/">trip to the Apple Store</a>, I&#8217;m sitting in Portland 256 for the <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/3373">Practical Erlang Programming</a>.  It&#8217;s being taught by <a href="http://en.oreilly.com/oscon2008/public/schedule/speaker/10595">Francesco Cesarini</a> of <a href="http://www.erlang-consulting.com/">Erlang Training and Consulting Ltd.</a></p>
<p>Over 90 people registered for this tutorial, and the room is almost full.  Save for the handful of available chairs, I&#8217;d feel guilty about auditing it instead of attending the <i>Real Time 3D on the Web with Open Source</i> I had originally registered for.  This will be a two and a half day course compressed into three hours.  Should be fun, and useful for <a href="http://en.oreilly.com/oscon2008/public/schedule/speaker/4961">Kevin&#8217;s</a> session tomorrow, <a href="http://en.oreilly.com/oscon2008/public/schedule/detail/3065">Beautiful Concurrency with Erlang</a>.  After seriously considering the relative merits and general usefulness of the tutorials, I decided <a href="http://www.erlang.org/">Erlang</a> would be much more interesting.  I had made my original choice with the equivalent of a dart board, so I don&#8217;t feel too bad about changing my mind.</p>
<p>The tutorial started with a quick tour of Erlang&#8217;s syntax.  It looks odd, but I&#8217;ve used Lisp and ML in the past, and I&#8217;m a rather good Perl hacker, so it isn&#8217;t proving too difficult to pick up.  The concept of pattern matching intrigues me.  It appears to use equivalency, in the mathematical sense to handle both boolean and assignment operations with the same syntax.  For example,</p>
<pre>
[A,B,C] = [1,2,3]    % A is 1, B is 2, C is 3
[A,B,C] = [1,2]      % error, size mismatch
[A,B,A] = [1,2,3]    % error, A already bound to 1
[A,B,A] = [1,2,1]    % okay, A bound to 1, then equivalent to 1
</pre>
<p>Shortly into the discussion of syntax, Francesco asked that anyone who hasn&#8217;t yet installed Erlang do so.  I executed <code>yum install erlang</code>, which pulled in unixODBC, tcl, and tk as dependencies.  Well, 45 megabytes and 45 minutes later&mdash;an impressive speed of 1 MBpm&mdash;I now have Erlang installed and ready to run.  Just in time for a 10 minute break.</p>
<p>During this first break, we were asked to do a simple exercise in Erlang: write a module, <code>boolean.erl</code>, that implements <code>b_not()</code>, <code>b_and()</code>, <code>b_or()</code>, and <code>b_nand()</code>, without using the built in logical operators.  I&#8217;ve been able to define the structure of the module, but I don&#8217;t know how boolean values are represented in Erlang, so I may have to wait until he gives us the answer.  Vim&#8217;s syntax highlighting tells me that <code>true</code> and <code>false</code> are reserved words, so I can use those.</p>
<p>The solution for this involves writing a simple truth table.  In Erlang, functions are subject to pattern matching in the same way that many programming languages allow for function overloading.  For the logical or, we start with the basic truth table:</p>
<pre>
b_or(true,true)   -&gt; true;
b_or(true,false)  -&gt; true;
b_or(false,true)  -&gt; true;
b_or(false,false) -&gt; false.
</pre>
<p>That&#8217;s downright simple and extremely easy to grasp on a conceptual level, particularly for anyone with any background in mathematics.  However, and this appeals to me as Perl hacker, Erlang allows the programmer to be lazy, but in a good way.  The null variable&mdash;as I&#8217;m calling it due to the analogy with <code>/dev/null</code> on Unix-like systems (or <code>undef</code> in Perl)&mdash;<code>_</code>, allows a kind of lazy matching:</p>
<pre>
b_or(false,false) -&gt; false;    % the only false case with OR
b_or(_,_)         -&gt; true.     % any other case is true
</pre>
<p>The other functions can be written in a similar way.</p>
<p>Back from the break, and the population of the room has thinned very slightly.  Francesco immediately jumped into conditional evaluation, starting with the <code>case</code> clause.  I suspect this may be one of the answers to the exercise.  He followed that with the <code>if</code> clause.  I find it interesting that he&#8217;s done it in that order.  In most languages, the <code>if</code> statement is a much simpler case (no pun intended) and is covered first, before moving into more complex territory.  I think I understand why, the two clauses are implemented in a very similar fashion.  I&#8217;m not sure how equivalent they are, I&#8217;d have to play with them a bit.</p>
<p>As with any functional language, Erlang has strong support for recursion as well as a handful of built in functions (BIFs) implemented in C to accomplish things that are difficult or impossible to do directly in Erlang.  After all, at a certain point, things like date and time require system calls.  Also available are convenience functions to do things like convert tuples to lists or back.</p>
<p>At the second, official, break&mdash;taken after an official entered the room to scold Francesco for being 15 minutes late&mdash;we were presented with two more exercises.  First, to write a function, <code>sum/1</code>, which, given a positive integer <code>N</code>, will return the sum of all the integers between 1 and <code>N</code>.  As an extension, write a function, <code>sum/2</code>, which, given two integers <code>N</code> and <code>M</code>, return the sum of the interval between them, first ensuring <code>N &lt;= M</code>.  Second, write a function, <code>create/1</code>, which will return the list 1 through <code>N</code> given <code>N</code> as its argument.  As an extension, write a function, <code>reverse_create/1</code>, which does the same in reverse.</p>
<p>As I suspected, both exercises are perfect candidates for recursion, which is quite simple to do in Erlang:</p>
<pre>
sum(N) when N &gt; 0 -&gt;
    N + sum(N-1);
sum(0) -&gt;
    0.
</pre>
<p>The simpler list creation function is actually the second, and is solved similarly, but by accumulating a list instead of adding to a sum (which is, actually, also a method of accumulation):</p>
<pre>
reverse_create(0) -&gt;
    [];
reverse_create(N) -&gt;
    [N|reverse_create(N-1)].
</pre>
<p>The first thing I notice is, again, how mathematical Erlang is.  The solution is written in exactly the same way I do it when I&#8217;m jotting down notes while thinking about how to solve the problem.  To me, the syntax is quite elegant.</p>
<p>After going over the solutions to the exercises, we moved into concurrency.  As with most languages worth using, Erlang has a <code>spawn()</code> BIF, used to create processes.  What&#8217;s interesting about spawning processes in Erlang is that the function to do it does not take a system command.  Rather, it takes another Erlang function to run.  It&#8217;s quite a bit more elegant (there&#8217;s that word again) than the equivalent <code>fork()</code> dance done in most imperative languages.</p>
<p>Communication between Erlang processes is done via message passing; data is never shared.  As with everything else, the method for doing so is quite elegant: <code>Pid2 ! {self(), foo}</code>.  Okay, maybe someone has to be me to find that elegant.</p>
<p>The whole process concept in Erlang is quite nice and, again, elegant.  It&#8217;s plain that it is the primary method by which systems in Erlang are designed.  So far, though, we&#8217;ve only seen trivial examples.  That&#8217;s okay, because this is only a three hour tutorial.  However, as Larry Wall once said about Perl: It makes the easy things easy and the hard things possible.  It&#8217;s a good litmus test for any language.  It&#8217;s far too early for me to pass any judgment on Erlang.  I&#8217;d like to use it in anger sometime, to see how it performs for me.  Perhaps I can get my local Perl Mongers interested in chatting about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2008-practical-erlang-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSCON 2008: Mastering Perl</title>
		<link>http://sirhc.us/oscon-2008-mastering-perl/</link>
		<comments>http://sirhc.us/oscon-2008-mastering-perl/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 18:56:49 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[oscon08]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sirhc.us/journal/?p=177</guid>
		<description><![CDATA[It&#8217;s early on Monday morning and I&#8217;m in my first tutorial session of the day, following the continental breakfast provided in Convention Hall E. I wasn&#8217;t overly impressed with the tutorial options this year. So, being who I am, I &#8230; <a href="http://sirhc.us/oscon-2008-mastering-perl/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s early on Monday morning and I&#8217;m in my first tutorial session of the day, following the continental breakfast provided in Convention Hall E.  I wasn&#8217;t overly impressed with the tutorial options this year.  So, being who I am, I mostly opted for the Perl track.  That brings me to where I sit now: D136, listening to <a href="http://www252.pair.com/comdog/">brian d foy</a> teach us about <a href="http://www252.pair.com/comdog/mastering_perl/">Mastering Perl</a>.  I almost didn&#8217;t attend this tutorial, since I&#8217;ve read the book and, while I found it excellent, I learned very little from it.  I took this to mean that I&#8217;ve already mastered Perl.  But, like I said, my options are limited&mdash;I&#8217;m not very interested in the introductory Python tutorial.</p>
<p>The idea behind Mastering Perl is not to talk about Perl to a group of Perl masters.  Instead, it&#8217;s about mastering Perl in the guild sense (and not of the <a href="http://en.wikipedia.org/wiki/Society_for_Creative_Anachronism">SCA</a> variety).  Back in the day, and still existing in some professions today, there was an apprentice system.  A neophyte&mdash;in today&#8217;s nomenclature, a noob&mdash;would begin acquiring skills under a master of the art.  As he progressed, he would be entrusted with more and more responsibility, until finally he became a master himself and took people under his own wings.</p>
<p>This <a href="http://en.wikipedia.org/wiki/Apprenticeship">apprenticeship</a> system, somewhat unfortunately, does not exist in the computing world.  That&#8217;s where brian d foy feels that <i>Mastering Perl</i> fits.  Lacking true masters, the book acts as a substitute.  Someday, we may even create a guild system.  But then we&#8217;d probably have to pay dues and follow rules, and that&#8217;s not very attractive.  That said, it&#8217;s the model I&#8217;m hoping to use at my own place of work.  I&#8217;d like to hire one or two developers who I can take under my own wing and mentor them in the ways of Perl and the grid.</p>
<p>The first two topics covered are tools for optimization, profiling and benchmarking.  Often mis-attributed to Donald Knuth, Tony Hoare once said, &#8220;Premature optimization is the root of all evil.&#8221;  What this means is that one should never assume what requires optimization.  Let the testing be the guide.</p>
<p>While profiling is objective, benchmarks, like statistics, are not always objective.  Everyone has an agenda and benchmarks are subjective.  Often, benchmarks are short-sighted.  For example, benchmarking code run time and attempting to optimize for it may not be worth the expense of the developer time required to make the requisite changes.  It&#8217;s worth analysing what is important before blindly following benchmarks.</p>
<p>I&#8217;ve been on the receiving end of misplaced premature optimization.  I worked with a development group that put far too much emphasis on achieving perfect results on their <a href="http://search.cpan.org/dist/Devel-Cover/">Devel::Cover</a> reports.  This led to strange bugs in their code, and a strong belief that &#8220;<a href="http://use.perl.org/~cgrau/journal/33924"><tt>new()</tt> doesn&#8217;t work that way</a>.&#8221;  As it turns out, their test suite was calling <tt>new()</tt> in two ways.  I forget what the second method was, but it was not used anywhere else in their code.  However, in order to get this test code to run, and get 100% coverage, they added code to the constructor for every class.  Code that prevented inheritance of the method.  The team then convinced themselves that constructors could not be inherited in Perl, rather than realizing that their own habits were the problem.</p>
<p>After the mid-morning break, we wrapped up the discussion on profiling and benchmarking, and moved into configuration.  This is a vital topic for anyone who desires the ability to pass a program off to users without being bothered to modify it later in response to users&#8217; desire to customize the program for a slightly different use.</p>
<p>External configuration, particularly via the command line, is something I depend on heavily, even in very simple Perl or Bourne shell scripts.  I almost always create command line options for performing a dry run or output debugging information.  Not only are these useful for development, they can live on in the final program, providing help to the final user, who more often than not is me.  Sometimes I will even add configuration to values that never change, just for when they eventually do.</p>
<p>Jumping past configuration, we move on to logging.  It&#8217;s really easy to add to a program, and it&#8217;s really useful to leave in a program when it&#8217;s released.  The ability to enable logging on the fly sure beats adding a bunch of <tt>print()</tt> calls in the code when it inevitably breaks at three in the morning.  The <a href="http://search.cpan.org/dist/Log-Log4perl/">Log::Log4perl</a> module is a particularly powerful method of adding logging to programs.  It&#8217;s well worth investigating for anyone who wants to easily add logging functionality to their code.</p>
<p>The final topic of the day is lightweight persistence.  It&#8217;s always nice to have data stick around between program invocations.  The easy way (and everything in the second half of the tutorial is easy) to add persistence to code is to not use DBI.  While DBI is powerful, it also tends to require a database server (ignoring SQLite for the moment).  Modules such as <a href="http://search.cpan.org/dist/Data-Dumper/">Data::Dumper</a>, <a href="http://search.cpan.org/dist/YAML/">YAML</a> or <a href="http://search.cpan.org/dist/Storable/">Storable</a> are ideal for easily storing and retrieving data in code.</p>
<p>After the tutorial, brian will be available at the <a href="http://www.powells.com/">Powell&#8217;s Books</a> mini store, located near the registration desk, to sign copies of <i>Mastering Perl</i>.  I already have a copy, thanks to my local <a href="http://sandiego.pm.org/">Perl Mongers</a> group, but it&#8217;s all marked up with the group name, and I wouldn&#8217;t mind having a signed copy.</p>
<p>Now it&#8217;s time for lunch, which is good, because I&#8217;m quite hungry.  I hope the conference-provided lunch is decent during the tutorials, as it was last year.</p>
<p>[tags]oscon, oscon08, perl[/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://sirhc.us/oscon-2008-mastering-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

