<?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; Variable roles</title>
	<atom:link href="http://p.einarsen.no/tag/variable-roles/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>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>
	</channel>
</rss>

