<?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>Hey, it&#039;s OPOWER! &#187; Dave Copeland</title>
	<atom:link href="http://www.heyitsopower.com/author/dave-copeland/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.heyitsopower.com</link>
	<description>Energy Efficiency Starts at /usr/home</description>
	<lastBuildDate>Tue, 27 Jul 2010 20:14:37 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Boxed primitives and ==</title>
		<link>http://www.heyitsopower.com/culture/boxed-primitives-and/</link>
		<comments>http://www.heyitsopower.com/culture/boxed-primitives-and/#comments</comments>
		<pubDate>Thu, 27 May 2010 18:25:06 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=215</guid>
		<description><![CDATA[One part of programming culture at OPOWER is to program defensively, providing useful information when contracts are violated.   What does this have to do with boxed primitives?  Getting an assertion message of &#8220;Person 1001&#8217;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243; seemed logically impossible, but was somehow true.
But [...]]]></description>
			<content:encoded><![CDATA[<p>One part of programming culture at OPOWER is to program defensively, providing useful information when contracts are violated.   What does this have to do with boxed primitives?  Getting an assertion message of &#8220;Person 1001&#8217;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243; seemed logically impossible, but was somehow true.</p>
<p>But first, let&#8217;s talk about defensive coding and how we do it.  For example:</p>
<pre name="code" class="java">/**
 * frobs the bar and baz.
 * @param bar the bar to frob; may not be null
 * @param baz the baz to from; must be positive
 */
public String frob(String bar, int baz) {
  if (bar.length() &gt; baz) {
    return bar.substring(baz);
  }
  else {
    return bar;
  }
}</pre>
<p>If the contract is violated by the caller, we will get a <code>NullPointerException</code> or some other <code>StringIndexOutOfBoundsException</code>.  Not too helpful.  Instead, we use an internal validator helper class to provide useful messages.  This is <strong>crucial</strong> for properly understanding bugs that occur in production; there&#8217;s nothing worse than coming into work to find a <code>NullPointerException</code> in your inbox and no clue what went wrong.</p>
<pre name="code" class="java">/**
 * frobs the bar and baz.
 * @param bar the bar to frob; may not be null
 * @param baz the baz to from; must be positive
 */
public String frob(String bar, int baz) {
  Validate.notNull(bar,"bar must not be null to frob");
  Validate.isTrue(baz &gt; 0,"baz must be positive");
  if (bar.length() &gt; baz) {
    return bar.substring(baz);
  }
  else {
    return bar;
  }
}</pre>
<p><code>Validate.*</code>  methods essentially throw <code>IllegalArgumentException</code> if what they are checking for fails.<br />
We use this pattern extensively, even in constructors of simple data-structure style objects.  This (plus keeping this things immutable) allows users of these objects to safely rely upon the <code>get</code> methods behaving properly. I had need of a class to hold both a <code>Person</code> (representing a website user) and a <code>Customer</code> (representing a utility-company customer).  This class (called, naturally, <code>PersonAndCustomer</code>), takes both objects in its constructor and requires that they are both non-null.  As a further sanity check, I wanted to make sure that the <code>Person</code>&#8217;s <code>customerId</code> matched the id of the <code>Customer</code> that was being passed in (i.e. that they represented the same actual human in the real world):</p>
<pre name="code" class="java">public PersonAndCustomer(Person p, Customer c) {
  Validate.notNull(p,"Person may not be null");
  Validate.notNull(c,"Customer may not be null");
  Validate.isTrue(p.getCustomerId() == c.getId(),
    "Person %d's customer id %d didn't match passed-in customer's id %d",
    p.getId(),
    p.getCustomerId(),
    c.getId());
  ...
}</pre>
<p>Looks pretty inocuous, right?  Well, because these objects are Hibernate-managed, all of our ids are <code>Long</code> and not <code>long</code>.  So, my <code>isTrue</code> validation is really checking that the person&#8217;s <code>customerId</code> <em>object</em> is the <em>same object</em> as the customer&#8217;s <code>id</code> object.  What&#8217;s worse, in several months of development and production deployment, these two objects <em>happened to be the same</em>.</p>
<p>Until this week; we were testing our application for a new client and I got the error posted above (&#8220;Person 1001&#8217;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243;).  It seems that much like how the JVM will re-use string objects, it also will sometimes re-use boxed objects as well.  But not always.  The fix for this is obvious, but I wanted to make sure I could actually recreate this situation.  So, I created a test that gave both the <code>Person</code> and <code>Customer</code> the same <em>value</em> for the customer id, but as different objects. and verified that the class could still be constructed.  Sure enough, the test failed.  The fix:</p>
<pre name="code" class="java">public PersonAndCustomer(Person p, Customer c) {
  Validate.notNull(p,"Person may not be null");
  Validate.notNull(c,"Customer may not be null");
  Validate.isTrue(p.getCustomerId().equals(c.getId()),
    "Person %d's customer id %d didn't match passed-in customer's id %d",
    p.getId(),
    p.getCustomerId(),
    c.getId());
  ...
}</pre>
<p>What&#8217;s interesting is that if one end of the <code>==</code> is a primitive, the JVM will unbox the other one and the test succeeds:</p>
<pre name="code" class="java">Long l1 = new Long(45L);
Long l2 = new Long(45L);

System.out.println(l1 == l2);      // false
System.out.println(l1.equals(l2)); // true
System.out.println(l1 == 45L);     // true!</pre>
<p>The moral of the story is to always know what you are comparing.  Might even be best to always use <code>.equals()</code> unless the compiler complains.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/culture/boxed-primitives-and/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dave&#8217;s Talk at ScalaDays 2010</title>
		<link>http://www.heyitsopower.com/code/daves-talk-at-scaladays-2010/</link>
		<comments>http://www.heyitsopower.com/code/daves-talk-at-scaladays-2010/#comments</comments>
		<pubDate>Mon, 03 May 2010 13:29:26 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=188</guid>
		<description><![CDATA[OPOWER graciously sent me to Switzerland this year for ScalaDays 2010.  I was lucky enough to be asked to present on &#8220;Sneaking Scala into the Enterprise&#8221;.  OPOWER sponsored the videography.  My talk, on starting to use Scala in your organization (based on my experience at OPOWER), is linked below; all the talks [...]]]></description>
			<content:encoded><![CDATA[<p>OPOWER graciously sent me to Switzerland this year for ScalaDays 2010.  I was lucky enough to be asked to present on &#8220;Sneaking Scala into the Enterprise&#8221;.  OPOWER sponsored the videography.  My talk, on starting to use Scala in your organization (based on my experience at OPOWER), is linked below; all the talks are online <a href="http://days2010.scala-lang.org/node/136">here</a>.<br />
<a href="http://days2010.scala-lang.org/node/138/169"><img class="alignnone size-full wp-image-189" title="Video | Scala Days 2010" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2010/04/Video-Scala-Days-2010.jpg" alt="Video | Scala Days 2010" width="648" height="388" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/code/daves-talk-at-scaladays-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tie Tuesday &#8211; more fun that it sounds</title>
		<link>http://www.heyitsopower.com/culture/tie-tuesday-more-fun-that-it-sounds/</link>
		<comments>http://www.heyitsopower.com/culture/tie-tuesday-more-fun-that-it-sounds/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 16:56:28 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=183</guid>
		<description><![CDATA[
The developers have an informal &#8220;Tie Tuesday&#8221; each work.  It&#8217;s exactly what it sounds like.  And, since you asked, yes, it is more fun to wear a tie when you don&#8217;t have to.  Not everyone does it every week, but this week, we had the best participation yet:

]]></description>
			<content:encoded><![CDATA[<p>
The developers have an informal &#8220;Tie Tuesday&#8221; each work.  It&#8217;s exactly what it sounds like.  And, since you asked, yes, it is more fun to wear a tie when you don&#8217;t have to.  Not everyone does it every week, but this week, we had the best participation yet:
</p>
<div id="attachment_182" class="wp-caption alignnone" style="width: 535px"><img src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2010/01/our-opower-mascot-on-tie-tuesday.jpeg" alt="Riley Dawg participates in tie tuesday" title="Our Mascot on Tie Tuesday" width="525" height="700" class="size-full wp-image-182" /><p class="wp-caption-text">Riley Dawg participates in tie tuesday</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/culture/tie-tuesday-more-fun-that-it-sounds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When adding more threads makes it all slower</title>
		<link>http://www.heyitsopower.com/code/when-adding-more-threads-makes-it-all-slower/</link>
		<comments>http://www.heyitsopower.com/code/when-adding-more-threads-makes-it-all-slower/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:07:25 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=154</guid>
		<description><![CDATA[I&#8217;ve been working on a new feature that requires analysis of each individual&#8217;s entire energy-use history.  In other words, I have a process that will touch every single bit of data in our database. This should be a rare thing, so if it takes a while, it&#8217;s not that big of a deal.  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new feature that requires analysis of each individual&#8217;s entire energy-use history.  In other words, I have a process that will touch <strong>every single bit of data</strong> in our database. This should be a rare thing, so if it takes a while, it&#8217;s not that big of a deal.  My initial implementation was on track to complete in&#8230;11 days.</p>
<p>My first thought was: there&#8217;s lots of blocking reading and writing from the database, so adding some threads should speed things up.  While one thread was analyzing Bob&#8217;s energy data, another could be fetching Mary&#8217;s, while another could be updating Joe&#8217;s meta-data with the results.  Or so I thought.</p>
<p>The more threads I added, the slower the entire thing became.  It turned out that <strong>the fastest implementation was a single-threaded one</strong>.  But why?  It all has to do with the diminishing returns one gets from scaling out.</p>
<p>If you think of a task as having a serial component, which cannot be broken up concurrently, and then multiple tasks which <strong>can</strong> be done concurrently, we can analyze the returns we get by increasing the number of available processors (threads, in my case).  This is <a href="http://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl&#8217;s Law</a> and is exemplified by the following equation (where &#8220;x&#8221; is the number of processors or threads, and &#8220;s&#8221; is the percentage of your overall task that must be serialized; &#8220;y&#8221; is the increase in speed you will see from scaling).<br />
<img class="alignnone size-full wp-image-157" title="Amdahl's Equation" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/amdahl.png" alt="Amdahl's Equation" width="97" height="34" /></p>
<p>When you graph this, it&#8217;s pretty obvious that there are diminishing returns to adding more threads/processors (the graph below assumes that 90% of the overall job can be done concurrently).  As we add threads, we get less and less of a gain in speed.<br />
But there&#8217;s still a gain to get, so what happened to me?</p>
<p><img class="alignnone size-medium wp-image-165" title="Graph of Amdahl's Equation with 10% of our task serialized" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/Picture-3-300x106.png" alt="Graph of Amdahl's Equation with 10% of our task serialized" width="300" height="106" /></p>
<p>Amdahl&#8217;s law is actually pretty optimistic.  It doesn&#8217;t account for the overhead required to synchronize the shared data.  If we account for this, with a new value &#8220;k&#8221; ( the percentage penalty for maintaining consistency), we see that increasing our processors/threads actually starts to hurt us (this equation is in red)!</p>
<p><img class="alignnone size-medium wp-image-161" title="Taking shared state synchronization into account" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/Coherence-300x105.png" alt="Taking shared state synchronization into account" width="300" height="105" /></p>
<p>In my case, almost all of this synchronization is happening within the database; it turns out that almost all the time my process needs is accessing data from the database.  So, I dialed it down to only one thread, and we should be done early next week.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/code/when-adding-more-threads-makes-it-all-slower/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slides on Improving Your Agile Development Process</title>
		<link>http://www.heyitsopower.com/development/slides-on-improving-your-agile-development-process/</link>
		<comments>http://www.heyitsopower.com/development/slides-on-improving-your-agile-development-process/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 17:32:40 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[devdays]]></category>
		<category><![CDATA[process improvement]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=131</guid>
		<description><![CDATA[Dead last, after the headline act, and after Joel Spolsky told everyone to go home, I did a lightning talk at DC&#8217;s recent DevDays (A StackOverflow production) on how we have used process metrics from our bug tracker to improve our process.
Improving your Agile Process
View more documents from David Copeland.

]]></description>
			<content:encoded><![CDATA[<p>Dead last, after the headline act, and after Joel Spolsky told everyone to go home, I did a lightning talk at DC&#8217;s recent DevDays (<a href="http://www.stackoverflow.com">A StackOverflow</a> production) on how we have used <a href="/development/measuring-our-awesomeness-iteration-by-iteration/">process metrics</a> from our bug tracker to improve our process.</p>
<div id="__ss_2359457" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Improving your Agile Process" href="http://www.slideshare.net/davetron5000/measuring-agile-process-shorter-2359457">Improving your Agile Process</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=measuringagileprocess-shorter-091027130310-phpapp01&amp;rel=0&amp;stripped_title=measuring-agile-process-shorter-2359457" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=measuringagileprocess-shorter-091027130310-phpapp01&amp;rel=0&amp;stripped_title=measuring-agile-process-shorter-2359457" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/davetron5000">David Copeland</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/development/slides-on-improving-your-agile-development-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A year-long analysis of snack consumption</title>
		<link>http://www.heyitsopower.com/culture/a-year-long-analysis-of-snack-consumption/</link>
		<comments>http://www.heyitsopower.com/culture/a-year-long-analysis-of-snack-consumption/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 21:53:27 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[doritos]]></category>
		<category><![CDATA[snacks]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=43</guid>
		<description><![CDATA[Consistently, month after month, the chips that get left in the giant &#8216;box-o-free-snacks&#8217; are:




Nacho Cheese Doritos.


Honorable Mentions: Fritos and Cool Ranch Doritos.
]]></description>
			<content:encoded><![CDATA[<p>Consistently, month after month, the chips that get left in the giant &#8216;box-o-free-snacks&#8217; are:
</p>
<p>
<img src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/IMG_0255-1024x768.jpg" alt="Doritos Are No Bueno" title="Doritos Are No Bueno" width="768" class="alignnone size-large wp-image-42" /></p>
<p>
Nacho Cheese Doritos.
</p>
<p>
<em>Honorable Mentions: Fritos and Cool Ranch Doritos</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/culture/a-year-long-analysis-of-snack-consumption/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Measuring our awesomeness iteration by iteration</title>
		<link>http://www.heyitsopower.com/development/measuring-our-awesomeness-iteration-by-iteration/</link>
		<comments>http://www.heyitsopower.com/development/measuring-our-awesomeness-iteration-by-iteration/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:00:47 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[process improvment]]></category>
		<category><![CDATA[qa]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=4</guid>
		<description><![CDATA[<p>
Like a lot of startups (and big companies!) we use iterative development: we break up our work into "stories" describing features and implement as many as we can in one month.  We then repeat that until we conquer the world.  But, if we can do more, or work more efficiently with each iteration, our goal of world domination will approach that much quicker :)
</p>
<p>
The easiest way to do that is to look at the bugs our QA staff find in the product updates.  Although we have a lot of automated tests, we still need some eyes on the applications to check for things like text overruns of our printed reports, or JavaScript weirdness in some <a href="http://blog.digg.com/?p=878">less-than-well-behaved</a>) browsers.
</p>]]></description>
			<content:encoded><![CDATA[<p>
Like a lot of startups (and big companies!) we use iterative development: we break up our work into &#8220;stories&#8221; describing features and implement as many as we can in one month.  We then repeat that until we conquer the world.  But, if we can do more, or work more efficiently with each iteration, our goal of world domination will approach that much quicker <img src='http://www.heyitsopower.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p>
The easiest way to do that is to look at the bugs our QA staff find in the product updates.  Although we have a lot of automated tests, we still need some eyes on the applications to check for things like text overruns of our printed reports, or JavaScript weirdness in some <a href="http://blog.digg.com/?p=878">less-than-well-behaved</a>) browsers.
</p>
<p>
After a few iterations, Anh (our beloved program manager) ran some queries on our bug-tracking database and, using some Excel magic, showed us numbers like &#8220;number of defects in the web application&#8221; and &#8220;average number of days a critical bug sat unassigned&#8221;.  This is good stuff; seeing hard data about what we&#8217;re doing lets us focus on inefficiency.  Since we release software every month (and launch new clients almost as frequently), this is a <b>huge</b> help in making each iteration better than the previous.
</p>
<p>
While Anh&#8217;s hand-jammed report was awesome, manually connecting SQLite and Excel is no fun for anyone.  I whipped up a basic Ruby application using <a href="http://www.sinatrarb.com/">Sinatra</a> to automate most of what we&#8217;d like to see.  We can now see how long critical defects site open and unfixed, as well as how many overall defects we&#8217;re fixing and even the <i>root source</i> of our defects (e.g. did we get the wrong requirements, or just mess up implementing them?)
</p>
<p>
We still need to show trends, however.  &#8220;Classic&#8221; thinking in software process improvement says to do that by dividing everything by lines of code; if we had 10 defects per 1,000 lines of code this month, but only 8 the following, we&#8217;re doing better.  This is not a great measure for us, since we are changing and enhancing our product (as opposed to writing fresh code each time), so we decided to normalize our measurements by the story points we assigned to the iteration.  This way, we can see charts like the one below (which says we are doing better each time):
</p>
<p><img src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/MetricsChart.png" alt="Metrics Chart" title="Metrics Chart" width="442" height="314" class="alignnone size-full wp-image-7" /></p>
<p>
This information is dead simple to collect; the burden on developers and testers when writing defects is almost nothing.  With only a priority, severity, and &#8220;source of defect&#8221;, we can collect a lot of advanced information about our development process &mdash; and make it better iteration by iteration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/development/measuring-our-awesomeness-iteration-by-iteration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
