<?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>The Shape of Code &#187; between</title>
	<atom:link href="http://shape-of-code.coding-guidelines.com/tag/between/feed/" rel="self" type="application/rss+xml" />
	<link>http://shape-of-code.coding-guidelines.com</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 20:42:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Implementing the between operation</title>
		<link>http://shape-of-code.coding-guidelines.com/2009/07/30/implementing-the-between-operation/</link>
		<comments>http://shape-of-code.coding-guidelines.com/2009/07/30/implementing-the-between-operation/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 01:09:08 +0000</pubDate>
		<dc:creator>Derek-Jones</dc:creator>
				<category><![CDATA[empirical]]></category>
		<category><![CDATA[between]]></category>
		<category><![CDATA[culture]]></category>
		<category><![CDATA[if statement]]></category>
		<category><![CDATA[semantics]]></category>

		<guid isPermaLink="false">http://shape-of-code.coding-guidelines.com/?p=106</guid>
		<description><![CDATA[What code do developers write to check whether a value lies between two bounds (i.e., a between operation)?  I would write (where MIN and MAX might be symbolic names or numeric literals): if &#40; x &#62;= MIN &#38;&#38; x &#60;= MAX &#41; that is I would check the lowest value first. Performing the test in [...]]]></description>
			<content:encoded><![CDATA[<p>What code do developers write to check whether a value lies between two bounds (i.e., a between operation)?  I would write (where <code>MIN</code> and <code>MAX</code> might be symbolic names or numeric literals):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> x <span style="color: #339933;">&gt;=</span> MIN <span style="color: #339933;">&amp;&amp;</span> x <span style="color: #339933;">&lt;=</span> MAX <span style="color: #009900;">&#41;</span></pre></div></div>

<p>that is I would check the lowest value first.  Performing the test in this order just seems the natural thing to do, perhaps because I live in a culture that writes left to write and a written sequence of increasing numbers usually has the lowest number on the left.</p>
<p>I am currently measuring various forms of <em>if-statement</em> conditional expressions that occur in visible source as part of some research on if/switch usage by developers and the <em>between</em> operation falls within the set of expressions of interest.  I was not expecting to see any usage of the form:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> x <span style="color: #339933;">&lt;=</span> MAX <span style="color: #339933;">&amp;&amp;</span> x <span style="color: #339933;">&gt;=</span> MIN <span style="color: #009900;">&#41;</span></pre></div></div>

<p>that is with the maximum value appearing first.  The first program measured  threw up seven instances of this usage, all with the minimum value being negative and in five cases the maximum value being zero.  Perhaps left to right ordering still applied, but to the absolute value of the bounds.</p>
<p>Measurements of the second and subsequent programs threw up instances that did not follow any of the patterns I had dreamt up.  Of the 326 <em>between</em> operations appearing in the measured source 24 had what I consider to be the unnatural order.  Presumably the developers using this form of <em>between</em> consider it to be natural, so what is their line of thinking?  Are they thinking in terms of the semantics behind the numbers (in about a third of cases symbolic constants appear in the source rather than literals) and this semantics has an implied left to right order?  Perhaps the authors come from a culture where the maximum value often appears on the left.</p>
<p>Suggestions welcome.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshape-of-code.coding-guidelines.com%2F2009%2F07%2F30%2Fimplementing-the-between-operation%2F&amp;title=Implementing%20the%20between%20operation" id="wpa2a_2"><img src="http://shape-of-code.coding-guidelines.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shape-of-code.coding-guidelines.com/2009/07/30/implementing-the-between-operation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

