<?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>Warren Seen &#187; java</title>
	<atom:link href="http://warrenseen.com/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://warrenseen.com/blog</link>
	<description>freelance software developer</description>
	<lastBuildDate>Wed, 03 Jun 2009 23:54:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Local company taking on Google over GWT?</title>
		<link>http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/</link>
		<comments>http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/#comments</comments>
		<pubDate>Mon, 02 Apr 2007 23:40:26 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[patents]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/</guid>
		<description><![CDATA[


Tasmania is a small place, which is why I&#8217;m surprised that very few people in the IT industry here have heard of Morfik, a Hobart based development company. Reading this morning&#8217;s Read/Write Web however, things may be about change there. As reported by Richard, slashdot are running a post about the Morfik patent which appears [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;padding:5px">
<a href="http://www.flickr.com/photos/warren_seen/444206142/"><img src="http://farm1.static.flickr.com/207/444206142_306575a4ce_m.jpg" alt="Morfik" /></a>
</div>
<p>Tasmania is a small place, which is why I&#8217;m surprised that very few people in the IT industry here have heard of <a href="http://www.morfik.com/">Morfik</a>, a Hobart based development company. Reading this morning&#8217;s <a href="http://www.readwriteweb.com/archives/morfik_patents_ajax_compiler.php">Read/Write Web</a> however, things may be about change there. As reported by Richard, <a href="http://yro.slashdot.org/article.pl?sid=07/04/02/1059211">slashdot</a> are running a post about the <a href="http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&#038;Sect2=HITOFF&#038;p=1&#038;u=%2Fnetahtml%2FPTO%2Fsearch-bool.html&#038;r=1&#038;f=G&#038;l=50&#038;co1=AND&#038;d=PG01&#038;s1=morfik&#038;OS=morfik&#038;RS=morfik">Morfik patent</a> which appears to be aimed squarely at Google&#8217;s <a href="http://code.google.com/webtoolkit/">GWT</a>.</p>
<p>I&#8217;m in two minds about this, as I always am about software patents. On the one hand, Morfik was clearly first to the party in terms of public release of a JavaScript compiler, according to the patent they had a provisional granted prior to the release of the GWT. On the other, I have to wonder how this is any different to the multitude of language translation techniques already out there, or at least whether it&#8217;s significantly inventive enough to pass the &#8220;not obvious to a practitioner in the field&#8221; test.</p>
<p>But hey, this wouldn&#8217;t be the first patent to be granted despite the obviousness of it to someone with half a brain. I mean, thank goodness the patent doesn&#8217;t mention Ruby, I guess that means <a href="http://www.rubyinside.com/16-rjs-resources-and-tutorials-for-rails-programmers-5.html">RJS</a> is safe!
</p>
<p><!--c803f5fd0a94c87801a54b068fb22c3e-->
</p>
<p><!--d6255acec078e3ea5472f22cbce239a8-->
</p>
<p><!--7ef154d3b0ecc4f6ac914533288de280-->
</p>
<p><!--0d4e8a0bf70f98b503dd59ca2f735a62--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The committer model in practice</title>
		<link>http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/</link>
		<comments>http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/#comments</comments>
		<pubDate>Tue, 28 Mar 2006 04:25:36 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/</guid>
		<description><![CDATA[Interesting article about the use of the &#8220;Committer Model&#8221; in commercial software development, borrowed from the open source community.
The committer model solves a few problems of open source distributed development, but the primary one is that of trust: in a developers intent and in their competence. There are other issues that push different buttons depending [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.artima.com/forums/flat.jsp?forum=270&#038;thread=153785">Interesting article</a> about the use of the &#8220;Committer Model&#8221; in commercial software development, borrowed from the open source community.</p>
<p>The committer model solves a few problems of open source distributed development, but the primary one is that of trust: in a developers intent and in their competence. There are other issues that push different buttons depending on the project, but in the end, these are just indicators of intent or competence.</p>
<p>Personally, I think this is a bit of an extreme approach in the average commercial development project &#8211; certainly for teams under 10 developers I would call it excessive &#8211; as the same issues don&#8217;t apply in a commercial project.</p>
<p>Firstly, you must implicitly trust the intent of the developers which you are paying to write the software &#8211; and if you don&#8217;t, why are they working for you to begin with? Secondly, if you&#8217;ve hired them, then you already have made a decision based on their competence.</p>
<p><span id="more-32"></span>Fair enough, you don&#8217;t leave the keys to the castle with them on the first day, but not allowing them to check into a revision control system AT ALL is just asking for trouble in my opinion.</p>
<p>Still, the fact remains that to ensure quality, you can&#8217;t have code that was just checked in being rolled straight into a release and expect it to work. There needs to be some sort of gating to ensure that code has been relatively well exercised before it makes it into a release build. So how to compromise?</p>
<p>The way we approach this issue is to maintain a &#8220;trunk&#8221;, the latest code in development, and release branches, eg 1.0-release, 1.1-release, etc. We have a team of anywhere up to six developers working on various facets of the code at any time. The rules are simple: </p>
<ol>
<li>don&#8217;t check into the trunk if your code won&#8217;t compile and pass our test suite.</li>
<li>if you have done significant work which has caused breakage, create a private branch until you can fulfill 1.</li>
<li>only one person is in charge of release &#8220;gating&#8221;, eg merging code from the trunk into a release branch.</li>
</ol>
<p>This approach provides the ability for all developers to grab the bleeding edge code, whilst ensuring that code that gets merged into release branches is vetted accordingly. Fixes are applied within the trunk, and backported to release branches if necessary (eg for patch distribution)</p>
<p>In the case of simple changes, this probably takes all of 5 minutes to confirm that the fix does what it needs to do. Bigger changes usually require consultation or a walkthrough with the developer responsible.</p>
<p>In essence, this still implements the same safeguards as the committer model, however you also capture more change history as developers are able to commit small changes as they are made, reducing the risk of introducing widespread errors, or losing large amounts of work through equipment failure.</p>
<p>Personally, it&#8217;s rare for me to do a day&#8217;s work without committing it all &#8211; I&#8217;ve seen a hard drive die overnight enough times to be paranoid.</p>
<p><!--81f6bdb2cdc4da127916df39e3166cfd-->
</p>
<p><!--043ce18299249aae52aa0ff27698ed4b-->
</p>
<p><!--81f6bdb2cdc4da127916df39e3166cfd--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to calculate standard deviation</title>
		<link>http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/</link>
		<comments>http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/#comments</comments>
		<pubDate>Mon, 13 Mar 2006 08:03:41 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/</guid>
		<description><![CDATA[When I started this blog last month, I thought &#8220;Standard Deviation&#8221; was a snappy title. Of course, I also knew about standard deviation as a statistical tool, however I didn&#8217;t expect that this overlap would cause Google search to drive 50+ visitors a month here looking for implementations of the standard deviation formula.
So as a [...]]]></description>
			<content:encoded><![CDATA[<p>When I started this blog last month, I thought &#8220;Standard Deviation&#8221; was a snappy title. Of course, I also knew about standard deviation as a statistical tool, however I didn&#8217;t expect that this overlap would cause Google search to drive 50+ visitors a month here looking for implementations of the <a href="http://en.wikipedia.org/wiki/Standard_Deviation#Definition_and_shortcut_calculation_of_standard_deviation">standard deviation formula</a>.</p>
<p>So as a &#8220;public service&#8221;, here is some code to figure standard deviation in Ruby and Java.</p>
<p>(disclaimer: no warranties as to correctness, particularly to the nth decimal place, don&#8217;t use this to run your home made nuclear reactor or air traffic control system, blah blah, etc, etc <img src='http://warrenseen.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</p>
<p><span id="more-29"></span>The algorithm I&#8217;ll be using is &#8220;borrowed&#8221; from wikipedia&#8217;s entry on <a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance">Algorithms to calculate variance</a>. Specifically, I&#8217;ll be using a variant of algorithm II, which is sourced from Knuth, except we&#8217;ll calculate the standard deviation for the population, rather than a sample. </p>
<p>As you should probably know, standard deviation is defined as the square root of the variance. If you didn&#8217;t know this, maybe you should go read about <a href="http://en.wikipedia.org/wiki/Standard_Deviation">standard deviation</a> first.</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c8577b2cb9af">
<div class="synthi_header" style="font-weight:bold;"> Java <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c8577b2cb9af').style.display='block';document.getElementById('plain_synthi_4c8577b2cb9af').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
/**
 * @param population an array, the population
 * @return the variance
 */
public double variance(double[] population) {
	long n = 0;
	double mean = 0;
	double s = 0.0;

	for (double x : population) {
		n++;
		double delta = x - mean;
		mean += delta / n;
		s += delta * (x - mean);
	}
	// if you want to calculate std deviation
	// of a sample change this to (s/(n-1))
	return (s / n);
}

/**
 * @param population an array, the population
 * @return the standard deviation
 */
public double standard_deviation(double[] population) {
	return Math.sqrt(variance(population));
}
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c8577b2cb9af">
<div class="synthi_header" style="font-weight:bold;"> Java <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c8577b2cb9af').style.display='block';document.getElementById('styled_synthi_4c8577b2cb9af').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="java" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/**</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> * @param population an array, the population</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> * @return the variance</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> */</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">double</span> variance<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">double</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> population<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">long</span> n = <span style="color: #cc66cc;">0</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">double</span> mean = <span style="color: #cc66cc;">0</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">double</span> s = <span style="color: #cc66cc;">0.0</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">double</span> x : population<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n++;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">double</span> delta = x &#8211; mean;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mean += delta / n;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s += delta * <span style="color: #66cc66;">&#40;</span>x &#8211; mean<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if you want to calculate std deviation</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// of a sample change this to (s/(n-1))</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>s / n<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/**</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> * @param population an array, the population</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> * @return the standard deviation</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> */</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">double</span> standard_deviation<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">double</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> population<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Math</span></a>.<span style="color: #006600;">sqrt</span><span style="color: #66cc66;">&#40;</span>variance<span style="color: #66cc66;">&#40;</span>population<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<p>example usage:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c8577b2d2ed6">
<div class="synthi_header" style="font-weight:bold;"> Java <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c8577b2d2ed6').style.display='block';document.getElementById('plain_synthi_4c8577b2d2ed6').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
double[] arr = { 1, 3, 24, 17, 12, 6, 14};
System.out.printf(&#034;%f&#034;, standard_deviation(arr));
  // prints 7.596992
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c8577b2d2ed6">
<div class="synthi_header" style="font-weight:bold;"> Java <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c8577b2d2ed6').style.display='block';document.getElementById('styled_synthi_4c8577b2d2ed6').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="java" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">double</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> arr = <span style="color: #66cc66;">&#123;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">24</span>, <span style="color: #cc66cc;">17</span>, <span style="color: #cc66cc;">12</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">14</span><span style="color: #66cc66;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">printf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%f&quot;</span>, standard_deviation<span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic;">// prints 7.596992 </span></div>
</li>
</ol>
</div>
</div>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c8577b2d7cf8">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c8577b2d7cf8').style.display='block';document.getElementById('plain_synthi_4c8577b2d7cf8').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
  def variance(population)
    n = 0
    mean = 0.0
    s = 0.0
    population.each { |x|
      n = n + 1
      delta = x - mean
      mean = mean + (delta / n)
      s = s + delta * (x - mean)
    }
    # if you want to calculate std deviation
    # of a sample change this to &#034;s / (n-1)&#034;
    return s / n
  end

  # calculate the standard deviation of a population
  # accepts: an array, the population
  # returns: the standard deviation
  def standard_deviation(population)
    Math.sqrt(variance(population))
  end
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c8577b2d7cf8">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c8577b2d7cf8').style.display='block';document.getElementById('styled_synthi_4c8577b2d7cf8').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> variance<span style="color:#006600; font-weight:bold;">&#40;</span>population<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; n = <span style="color:#006666;">0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; mean = <span style="color:#006666;">0.0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; s = <span style="color:#006666;">0.0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; population.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |x|</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; n = n + <span style="color:#006666;">1</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; delta = x &#8211; mean</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; mean = mean + <span style="color:#006600; font-weight:bold;">&#40;</span>delta / n<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; s = s + delta * <span style="color:#006600; font-weight:bold;">&#40;</span>x &#8211; mean<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># if you want to calculate std deviation</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># of a sample change this to &quot;s / (n-1)&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> s / n</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># calculate the standard deviation of a population</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># accepts: an array, the population</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;"># returns: the standard deviation</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> standard_deviation<span style="color:#006600; font-weight:bold;">&#40;</span>population<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Math.<span style="color:#9900CC;">sqrt</span><span style="color:#006600; font-weight:bold;">&#40;</span>variance<span style="color:#006600; font-weight:bold;">&#40;</span>population<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
<p>example usage:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c8577b2da408">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c8577b2da408').style.display='block';document.getElementById('plain_synthi_4c8577b2da408').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
 puts standard_deviation([1, 3, 24, 17, 12, 6, 14])
 # prints 7.59699188589047
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c8577b2da408">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c8577b2da408').style.display='block';document.getElementById('styled_synthi_4c8577b2da408').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">puts</span> standard_deviation<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">24</span>, <span style="color:#006666;">17</span>, <span style="color:#006666;">12</span>, <span style="color:#006666;">6</span>, <span style="color:#006666;">14</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color:#008000; font-style:italic;"># prints 7.59699188589047 </span></div>
</li>
</ol>
</div>
</div>
<p>If you found this at all useful, (or have spotted a bug), please leave a comment to that effect&#8230;
</p>
<p><!--d94bd1e207fd7b2827a6a2b9f29b6da5--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t touch my braces!</title>
		<link>http://warrenseen.com/blog/2006/02/24/dont-touch-my-braces/</link>
		<comments>http://warrenseen.com/blog/2006/02/24/dont-touch-my-braces/#comments</comments>
		<pubDate>Thu, 23 Feb 2006 23:46:23 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2006/02/24/dont-touch-my-braces/</guid>
		<description><![CDATA[No, it&#8217;s not that my pants will fall down if you do, but my Java code might get a bit less intelligible.
Ed Burnette blogs on a nasty little &#8220;feature&#8221; of Eclipse. First, a little background
Java, C, and C++ share a little syntactic quirk that has bitten all developers on the rear from time to time. [...]]]></description>
			<content:encoded><![CDATA[<p>No, it&#8217;s not that my pants will fall down if you do, but my Java code might get a bit less intelligible.</p>
<p>Ed Burnette <a title="Is your IDE *too* helpful?" href="http://blogs.zdnet.com/Burnette/?p=16&#038;tag=nl.e027">blogs on</a> a nasty little &#8220;feature&#8221; of Eclipse. First, a little background</p>
<blockquote><p>Java, C, and C++ share a little syntactic quirk that has bitten all developers on the rear from time to time. Take a look at this code:</p>
<blockquote><p>if (condition)<br />
doSomething();<br />
doSomethingElse();</p>
</blockquote>
<p>The &#8220;doSomethingElse();&#8221; code will always be executed regardless of the value of the condition because only the &#8220;doSomething();&#8221; statement is considered part of the &#8220;if&#8221;.</p>
</blockquote>
<p>This has bitten me on more than one occasion on source code that has been checked into our repository and edited by multiple people, causing the indentation to get screwed up (eg tabs and spaces). Especially when you&#8217;re scanning code you&#8217;re not familiar with, indentation is a key indication of code blocks and nesting.</p>
<p><span id="more-23"></span><br />
My preference is to  always use braces for code blocks, i feel it&#8217;s far more consistent. Ed says:</p>
<blockquote><p>Some programmers find this overly verbose. It wastes a line on your screen, or two lines if you like putting the opening brace on its own line. However I would argue that maintainability and idiot-proofing the code is much more important.</p>
<p>The reason I mention all this is that some IDEs will helpfully offer to remove these &#8220;extraneous&#8221; braces for you.</p>
<p><em>This is evil.</em></p>
</blockquote>
<p>Too right it&#8217;s evil. Since when has verbosity been a bad thing when it improves maintainability and understanding &#8220;at a glance&#8221; ?</p>
<p>Much as a dislike the line breaking feature in Eclipse when you use it to format code&#8230; I don&#8217;t care if my lines are excessively long, I&#8217;d rather have a long line that makes sense, than to break the lines in a non-intuitive manner, which Eclipse is wont to do.<br />
So rest assured Ed, when I download my copy of Eclipse 3.2, this feature is well and truly staying off.
</p>
<p><!--1d772cf7122c27853d2fcbf8508640dc-->
</p>
<p><!--fcb7603a713d43f8e06f9ea4ca12f0e0-->
</p>
<p><!--fcb7603a713d43f8e06f9ea4ca12f0e0-->
</p>
<p><!--1d772cf7122c27853d2fcbf8508640dc--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2006/02/24/dont-touch-my-braces/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
