<?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; Culture</title>
	<atom:link href="http://www.heyitsopower.com/category/culture/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>Cinco de Failure</title>
		<link>http://www.heyitsopower.com/culture/cinco-de-failure/</link>
		<comments>http://www.heyitsopower.com/culture/cinco-de-failure/#comments</comments>
		<pubDate>Wed, 05 May 2010 16:40:33 +0000</pubDate>
		<dc:creator>Tom Vaughan</dc:creator>
				<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=196</guid>
		<description><![CDATA[If you&#8217;ve ever seen Yoni or Jeff K, you would know that I have absolutely no chance of competing in a facial-hair competition with them on raw natural talent.  Thus, for the 2010 Cinco de Mustache event, I felt compelled to compete on ingenuity and engineering.
To the disgust of myself and my wife, I collected [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever seen Yoni or Jeff K, you would know that I have absolutely no chance of competing in a facial-hair competition with them on raw natural talent.  Thus, for the 2010 Cinco de Mustache event, I felt compelled to compete on ingenuity and engineering.</p>
<p>To the disgust of myself and my wife, I collected shavings for approximately 4 months in a plastic cream cheese jar labeled &#8220;Not Cream Cheese.&#8221;</p>
<p>This last weekend, I took a trip to AC Moore Arts &amp; Crafts and bought some clay.  I fashioned a mold into that clay of a mustache that would dominate all other mustaches.</p>
<p>Into that mold, I poured elmer&#8217;s glue, hair shavings, 14 gauge electrical copper wiring, more hair, more glue, more hair.</p>
<p><a title="cinco_assembly by Tom_Vaughan, on Flickr" href="http://www.flickr.com/photos/tom_vaughan/4581864452/"><img src="http://farm5.static.flickr.com/4035/4581864452_ba14d1b7ab.jpg" alt="cinco_assembly" width="375" height="500" /></a></p>
<p>This morning, the <em>plan </em>was to simply glue the assembled mustache on to my real mustache.  Unfortunately, the plan involved entirely too much super glue and the assembled mustache pieces proved to be entirely too heavy.  My previous experience with krazy-glue-on-skin is probably like most people&#8217;s&#8230;stick your thumb and index finger together.  Thanks to callouses, a lack of hair on your fingertips and the relative strength of your digits, it&#8217;s not that big of a deal.  I also don&#8217;t remember the glue <em>burning like lava on contact.</em></p>
<p>A split second before squirting a liberal does of krazy glue on the mustache I wondered: &#8220;is this really a good idea?&#8221;  But not wanting to pysch myself out, I quickly brought the assembled mustache up to my lip and pressed down hard.</p>
<p>The first thing I remember thinking is that this was going to look <em>really</em> good.  Like, maybe champion-quality entry.</p>
<p>That thought was quickly replaced with a rising alarm about the rapidly increasing burning sensation I was experiencing between the mustache and my lip.  That alarm was then replaced with the growing realization that I was inhaling quite a bit of vapor and that my throat was starting to burn.</p>
<p>Not-quite-panicked, but not totally calm either, I gently tried to remove the mustache and got as far as pulling my lip about an inch off my face before giving up.  Over the next 10 minutes I was able to saw, snip and shave the &#8217;stache down with a combination of electric shaver, electrical pliers, scissors and razor blade.  By that time, of course, the fumes had dissipated and the burning was just a low heat and my grand mustache plans were wrecked.</p>
<p><a title="cinco_fail_2 by Tom_Vaughan, on Flickr" href="http://www.flickr.com/photos/tom_vaughan/4581214623/"><img src="http://farm5.static.flickr.com/4021/4581214623_05e508de62.jpg" alt="cinco_fail_2" width="375" height="500" /></a></p>
<p><em>The redness of my eyes is due to the fumes and pain.</em></p>
<p>There&#8217;s always 2011&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/culture/cinco-de-failure/feed/</wfw:commentRss>
		<slash:comments>1</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>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>The Cheated Frogs of Vim</title>
		<link>http://www.heyitsopower.com/culture/the-cheated-frogs-of-vim/</link>
		<comments>http://www.heyitsopower.com/culture/the-cheated-frogs-of-vim/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 14:00:30 +0000</pubDate>
		<dc:creator>Tom Vaughan</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=26</guid>
		<description><![CDATA[We're still too small of a company to have more than 1 or 2 logical groupings of the development team, and before today they've been basically "the web team" and "everyone else."  Of course, there's a lot of cross-pollination and everything nowadays ultimately manifests itself somehow as "'web".

Still, the "everyone else" paint brush was wearing thin.  In addition to the "web team", we had "the scale team" (a.k.a "Ops R&#038;D") and "the AMI team" and "the core team" and "the report team". . .but most of those were "teams" averaged size 1 and their membership varied from iteration-to-iteration.]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re still too small of a company to have more than 1 or 2 logical groupings of the development team, and before today they&#8217;ve been basically &#8220;the web team&#8221; and &#8220;everyone else.&#8221;  Of course, there&#8217;s a lot of cross-pollination and everything nowadays ultimately manifests itself somehow as &#8220;&#8216;web&#8221;.</p>
<p>Still, the &#8220;everyone else&#8221; paint brush was wearing thin.  In addition to the &#8220;web team&#8221;, we had &#8220;the scale team&#8221; (a.k.a &#8220;Ops R&amp;D&#8221;) and &#8220;the AMI team&#8221; and &#8220;the core team&#8221; and &#8220;the report team&#8221;. . .but most of those were &#8220;teams&#8221; averaged size 1 and their membership varied from iteration-to-iteration.</p>
<p>Sick of referring to ourselves with a hand-wave and a &#8220;you-know. . .the non-web-team,&#8221; I plugged our names in to an acronym engine and we found the perfect name for ourselves:</p>
<p><strong><em>The Cheated Frogs of Vim</em></strong></p>
<p>While I put in my fair share of vi time in previous development gigs, I&#8217;m a little too fond of modern debuggers to go whole-hog with Vim as my &#8220;IDE.&#8221;  Dave, on the other hand, is pretty hard-core with his Vim skills, so our new team name may have some sticking power.</p>
<p>Our wizard graphics guy even cooked up a logo for us:</p>
<div id="attachment_27" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-27" title="CheatedFrogs" src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/CheatedFrogs-300x300.png" alt="New dev team logo!" width="300" height="300" /><p class="wp-caption-text">New dev team logo!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/culture/the-cheated-frogs-of-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
