<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Daveblog5000</title>
 <link href="http://www.naildrivin5.com/blog/atom.xml" rel="self"/>
 <link href="http://www.naildrivin5.com/blog/"/>
 <updated>2010-07-30T07:48:11-04:00</updated>
 <id>http://www.naildrivin5.com/blog</id>
 <author>
   <name>Dave Copeland</name>
   <email>davec@naildrivin5.com</email>
 </author>

 
 <entry>
   <title>In "Offense" of Scala's Option class; a guarded defense of Cédric's rant</title>
   <link href="http://www.naildrivin5.com/blog/2010/07/30/in-offense-of-scala-option.html"/>
   <updated>2010-07-30T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/07/30/in-offense-of-scala-option</id>
   <content type="html">&lt;p&gt;In a &lt;a href='http://beust.com/weblog/2010/07/28/why-scalas-option-and-haskells-maybe-types-wont-save-you-from-null/'&gt;recent blog entry&lt;/a&gt;, Cédric Beust calls out scala&amp;#8217;s &lt;code&gt;Option&lt;/code&gt; class as nothing more significant than null checks. Commenters rightly set him straight that the thesis of his blog post was marred by an ignorance of idiomatic use of the class.&lt;/p&gt;

&lt;p&gt;But, it&amp;#8217;s hard to really blame Cédric, when you look at what he had to go on. Odersky&amp;#8217;s book states that one should use pattern matching with &lt;code&gt;Option&lt;/code&gt;, and the scaladoc for Option is just abysmal:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This class represents optional values. Instances of Option are either instances of case class Some or it is case object None.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the &lt;em&gt;entire&lt;/em&gt; description of the class, no examples, nothing. Worse, the method that commenters called out as idiomatic, &lt;code&gt;flatMap&lt;/code&gt;, has the following description:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If the option is nonempty, return a function applied to its value. Otherwise return None.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is &lt;em&gt;not&lt;/em&gt; what &lt;code&gt;Option#flatMap&lt;/code&gt; actually appears to do (nor is documented to do; it&amp;#8217;s documented to return an &lt;code&gt;Option[B]&lt;/code&gt;!):&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;s&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='nc'&gt;Some&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='nc'&gt;None&lt;/span&gt;
&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='nc'&gt;Some&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;}&lt;/span&gt;
&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;s&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;flatMap&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='nc'&gt;Some&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;foobar&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;flatMap&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='nc'&gt;None&lt;/span&gt;
&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='n'&gt;s&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;flatMap&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;r&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt; &lt;span class='kt'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;java.lang.String&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='nc'&gt;Some&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;foobar&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;r&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getClass&lt;/span&gt;
&lt;span class='n'&gt;res6&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt; &lt;span class='kt'&gt;java.lang.Class&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='k'&gt;_&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;scala&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;Some&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It certainly doesn&amp;#8217;t call itself out as &amp;#8220;the way&amp;#8221; to use Option. A simple example in the scaladoc could have gone a long way.&lt;/p&gt;

&lt;p&gt;So, angry post + helpful commenters == problem solved, right?&lt;/p&gt;

&lt;p&gt;Wrong.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Option&lt;/code&gt; class is, really, an implementation of the &lt;a href='http://en.wikipedia.org/wiki/Null_Object_pattern'&gt;NullObject&lt;/a&gt; pattern, and a more elegant way to handle optional values. In scala, we might have this method signature:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='cm'&gt;/**&lt;/span&gt;
&lt;span class='cm'&gt; * Updates the full name&lt;/span&gt;
&lt;span class='cm'&gt; * @param lastName the last name&lt;/span&gt;
&lt;span class='cm'&gt; * @param firstName the first name&lt;/span&gt;
&lt;span class='cm'&gt; */&lt;/span&gt;
&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;updateName&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt; &lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;])&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This means &amp;#8220;update my name; lastName is required and firstName is optional&amp;#8221;. In java, this method might look like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='cm'&gt;/**&lt;/span&gt;
&lt;span class='cm'&gt; * Updates the full name&lt;/span&gt;
&lt;span class='cm'&gt; * @param lastName the last name, may not be null&lt;/span&gt;
&lt;span class='cm'&gt; * @param firstName the first name, may be null&lt;/span&gt;
&lt;span class='cm'&gt; */&lt;/span&gt;
&lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;updateName&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;String&lt;/span&gt; &lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt; &lt;span class='n'&gt;String&lt;/span&gt; &lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='kc'&gt;null&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;throw&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nf'&gt;IllegalArgumentException&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;lastName required&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='n'&gt;StringBuffer&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;StringBuffer&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;firstName&lt;/span&gt; &lt;span class='o'&gt;!=&lt;/span&gt; &lt;span class='kc'&gt;null&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;append&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt;
        &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;append&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;fullName&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;toString&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So, what&amp;#8217;s the right way to do it in Scala? According to the commentors:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;updateName&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt; &lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;])&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Unit&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;StringBuffer&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;foreach&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;append&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;append&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Yech. Does anyone else think that calling a method called &amp;#8220;foreach&amp;#8221; on our &amp;#8220;optional value&amp;#8221; is just nonsensical? Or that the &lt;em&gt;idiomatic way&lt;/em&gt; to treat an optional value is &lt;em&gt;as a collection&lt;/em&gt;, e.g. by using the &lt;code&gt;for&lt;/code&gt; comprehension? This just feels hacky. Naming is one of the most important (and challenging) things in software engineering, and &lt;code&gt;Option&lt;/code&gt;&amp;#8217;s API is an utter failure (even its name is wrong; when one has &lt;em&gt;an option&lt;/em&gt;, one typicaly has many choices, not just one or nothing. &lt;em&gt;Optional&lt;/em&gt; is really what is meant here, so why are we afraid of adding a few more letters? Especially given how &amp;#8220;precise&amp;#8221; some of the documentation is, mathematically speaking, why are we not being precise with English?). If &lt;code&gt;Option&lt;/code&gt; is just shorthand for a &amp;#8220;list of zero or one elements&amp;#8221;, and we get no better methods than what comes with &lt;code&gt;List&lt;/code&gt;, then what&amp;#8217;s even the point of the class?&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not saying we remove all the collection methods from &lt;code&gt;Option&lt;/code&gt;, but how about a throwing us a bone to make our code readable and learnable without running to the scaladoc (or REPL) to see what&amp;#8217;s going on? I mean, there&amp;#8217;s a method on &lt;code&gt;Option&lt;/code&gt; called &lt;code&gt;withFilter&lt;/code&gt; whose documented purpose (I&amp;#8217;m not making this up) is: &amp;#8220;Necessary to keep Option from being implicitly converted to Iterable in for comprehensions&amp;#8221;. Am I expected to believe that it&amp;#8217;s ok to have &lt;em&gt;this&lt;/em&gt; hacky pile of cruft, but we can&amp;#8217;t get a readable method for &amp;#8220;do something to the contents if they are there&amp;#8221;?&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;A&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt; 
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;ifValue&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;U&lt;/span&gt;&lt;span class='o'&gt;](&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='kt'&gt;A&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;U&lt;/span&gt; &lt;span class='o'&gt;)&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Unit&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;foreach&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;unlessValue&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;U&lt;/span&gt;&lt;span class='o'&gt;](&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt; &lt;span class='o'&gt;()&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;U&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Unit&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;isEmpty&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;updateName&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt; &lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;])&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Unit&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;StringBuffer&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;lastName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;ifValue&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;append&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;append&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;firstName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;)&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Which would be less surprising? Couple this with some better scaladoc:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='cm'&gt;/** This class represents an optional value.  &lt;/span&gt;
&lt;span class='cm'&gt; *&lt;/span&gt;
&lt;span class='cm'&gt; * To use as a null object:&lt;/span&gt;
&lt;span class='cm'&gt; * val optional = getSomePossiblyOptionalValue&lt;/span&gt;
&lt;span class='cm'&gt; * &amp;lt;pre&amp;gt;&lt;/span&gt;
&lt;span class='cm'&gt; * option.ifValue { (actualValue) =&amp;gt; &lt;/span&gt;
&lt;span class='cm'&gt; *   // do things with the value, if it was there&lt;/span&gt;
&lt;span class='cm'&gt; * }&lt;/span&gt;
&lt;span class='cm'&gt; * &amp;lt;/pre&amp;gt;&lt;/span&gt;
&lt;span class='cm'&gt; * or&lt;/span&gt;
&lt;span class='cm'&gt; * &amp;lt;pre&amp;gt;&lt;/span&gt;
&lt;span class='cm'&gt; * optional.unlessValue { log.debug(&amp;quot;missing optional value&amp;quot;) }&lt;/span&gt;
&lt;span class='cm'&gt; * &amp;lt;/pre&amp;gt;&lt;/span&gt;
&lt;span class='cm'&gt; * &lt;/span&gt;
&lt;span class='cm'&gt; * To use as a Monad or collection:&lt;/span&gt;
&lt;span class='cm'&gt; * &amp;lt;pre&amp;gt;&lt;/span&gt;
&lt;span class='cm'&gt; * val first8upper = option.flatMap( (y) =&amp;gt; Some(y.toUpperCase) ).&lt;/span&gt;
&lt;span class='cm'&gt; *                          flatMap( (y) =&amp;gt; Some(y.substring(0,8)) )&lt;/span&gt;
&lt;span class='cm'&gt; * &amp;lt;/pre&amp;gt;&lt;/span&gt;
&lt;span class='cm'&gt; */&lt;/span&gt;
&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Option&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;T&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='c1'&gt;// etc.&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;With these examples, you cover the two main uses of this class, show newcomers how to use it, and demonstrate its superiority over null checks.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s frustrating to see this, because Scala has so much potential to be a lucid, accessible, readable language, but API usability and learnability are just not prioties. Scala needs to take some lessons from Ruby in terms of API design (and Java in terms of API documentation).&lt;/p&gt;

&lt;p&gt;Of course, none of this &lt;em&gt;does&lt;/em&gt; save you from null, because Scala is perfectly happy to assign null to anything. It kinda makes the whole thing seem a bit pointless.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>My first iPhone App - Part 5</title>
   <link href="http://www.naildrivin5.com/blog/2010/07/18/iphone-app-part-5.html"/>
   <updated>2010-07-18T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/07/18/iphone-app-part-5</id>
   <content type="html">&lt;p&gt;&lt;em&gt;See &lt;a href='/blog/2010/06/23/iphone-app-part-1.html'&gt;Part 1&lt;/a&gt;, &lt;a href='/blog/2010/06/27/iphone-app-part-2.html'&gt;Part 2&lt;/a&gt;, &lt;a href='/blog/2010/06/29/iphone-app-part-3.html'&gt;Part 3&lt;/a&gt;, and &lt;a href='/blog/2010/07/08/iphone-app-part-4.html'&gt;Part 4&lt;/a&gt; first&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been working on the app more than my recent lack of blog entries indicates. At this point, I have what could roughly be called a beta version; almost all the features are there, and things seem to be generally working pretty well.&lt;/p&gt;

&lt;h2 id='user_experience'&gt;User Experience&lt;/h2&gt;

&lt;p&gt;The biggest change in the UX is the ability to add tasting notes, date tasted, and location tasted. This is a new screen accessible from the main entry screen. The most obvious way to do this in my mind, was a big button at the bottom:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_new_wine_5.jpg' alt='New Add Screen' /&gt;&lt;/p&gt;

&lt;p&gt;In designing the new screen, the &amp;#8220;where tasted&amp;#8221; and &amp;#8220;when tasted&amp;#8221; were straightforward; I used stock controls. For the tasting notes, I needed a &lt;code&gt;UITextView&lt;/code&gt;, which is akin to an HTML &lt;code&gt;TEXTAREA&lt;/code&gt;. The visual appearance of this control is pretty lacking compared to the &lt;code&gt;UITextField&lt;/code&gt;; there is no nice beveled edge, no rounded corners, and no placeholder text. I really just wanted a multi-line field much like the &lt;code&gt;UITextField&lt;/code&gt;, but there is nothing available to create that.&lt;/p&gt;

&lt;p&gt;So, I hacked something together.&lt;/p&gt;

&lt;p&gt;An option for the &lt;code&gt;UITextField&lt;/code&gt;&amp;#8217;s appearance is to have a beveled edge with square corners. In this configuration, you can adjust the height of the text field. So, I placed such a field on the screen and sized it about the size of my tasting notes field and made the background color white. I then put the tasting notes field on top of it, with a clear background color, and, well, it looked pretty good:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_new_wine_details.jpg' alt='Details Screen' /&gt;&lt;/p&gt;

&lt;p&gt;I then implemented some &lt;code&gt;UITextViewDelegate&lt;/code&gt; methods to give the apperance of placeholder text:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kt'&gt;BOOL&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='nl'&gt;textViewShouldBeginEditing:&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;UITextView&lt;/span&gt; &lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='n'&gt;textView&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;([&lt;/span&gt;&lt;span class='n'&gt;textView&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt; &lt;span class='nl'&gt;isEqualToString:&lt;/span&gt;&lt;span class='n'&gt;DEFAULT_TASTING_NOTES_TEXT&lt;/span&gt;&lt;span class='p'&gt;])&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;textView&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s'&gt;@&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;YES&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kt'&gt;void&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='nl'&gt;textViewDidEndEditing:&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;UITextView&lt;/span&gt; &lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='n'&gt;textView&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;([&lt;/span&gt;&lt;span class='n'&gt;textView&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt; &lt;span class='n'&gt;length&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;textView&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;DEFAULT_TASTING_NOTES_TEXT&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I considered using some third-party controls that mimic this behavior, but didn&amp;#8217;t want to get side-tracked adding new frameworks to my app at this point.&lt;/p&gt;

&lt;h2 id='user_testing'&gt;User Testing&lt;/h2&gt;

&lt;p&gt;Once I had this, I handed my phone to Amy for some more user testing; She brought up a few obvious things that I had completely internalized and begun ignoring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clicking &amp;#8220;Save&amp;#8221; on the details screen brought you back to the &amp;#8220;new wine&amp;#8221; screen, instead of just saving and bringing you back to the top. A minor but obvious annoyance.&lt;/li&gt;

&lt;li&gt;She kept tapping on the &amp;#8220;Choose Varietal&amp;#8221; text field, thinking that would bring up the varietal chooser, instead of clicking the much smaller blue &amp;#8220;disclosure&amp;#8221; button&lt;/li&gt;

&lt;li&gt;She was a bit sad that the wines we had entered in the app would not be available on our shared Google Spreadsheet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To smooth the navigation after saving, I used a stock feature of the &lt;code&gt;UINavigationController&lt;/code&gt; to &amp;#8220;pop&amp;#8221; more than once up the chain. Since my design of the details screen used Apple&amp;#8217;s delegate pattern (essentially, the &amp;#8220;add new wine&amp;#8221; view controller was the delegate to the details view&amp;#8217;s lifecycle; when you click &amp;#8220;Save&amp;#8221; on the detail view, it triggers a callback in the &amp;#8220;add new wine&amp;#8221; view controller; the perfect place to save before the detail view controller popped back two screens).&lt;/p&gt;

&lt;p&gt;The problem with the &amp;#8220;Choose Varietal&amp;#8221; control had bugged me, too, but I got used to it and didn&amp;#8217;t think about it. The solution was very simple, though hacky. I placed a clear button on top of the field the exact size of the field and had it trigger the same action as the blue disclosure button. Problem solved.&lt;/p&gt;

&lt;p&gt;As to maintaining the list up on Google Docs, I think I may need to implement this sooner rather than later; I think it&amp;#8217;s important to be able to get your data out of an application, and Google Docs is a reasonably user-friendly way to do it (as opposed to emailing some CSV file).&lt;/p&gt;

&lt;h2 id='other_random_bits'&gt;Other Random Bits&lt;/h2&gt;

&lt;p&gt;I still didn&amp;#8217;t get around to setting up iCuke for testing; I really should because I don&amp;#8217;t know what missing &lt;code&gt;retain&lt;/code&gt; calls might be lurking. I also finally created an icon, using a picture I took in Napa. Not sure I like it, but it beats the white blob:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_icon.png' alt='Icon' /&gt;&lt;/p&gt;

&lt;p&gt;(Taken from &lt;a href='http://www.flickr.com/photos/davetron5000/3805675435/'&gt;my original&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Finally, the app no longer starts up on the actual device. A seemingly serious problem that I assume would be remedied by a re-install from scratch, however I have a few wines that I&amp;#8217;ve added and don&amp;#8217;t particularly wanted to lose them. Not sure how I could gain access to the SQL database to get them out, but I&amp;#8217;m currently downloading the 4.0.1 update for my phone and the 2+ GB SDK update (!).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;As a followup, I had to re-install the application from scratch, though I was able to access the SQLite database from an iTunes backup. I &lt;em&gt;really&lt;/em&gt; need to implement a quicker backup/export mechanism&amp;#8230;&lt;/em&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>My first iPhone App - Part 4</title>
   <link href="http://www.naildrivin5.com/blog/2010/07/08/iphone-app-part-4.html"/>
   <updated>2010-07-08T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/07/08/iphone-app-part-4</id>
   <content type="html">&lt;p&gt;&lt;em&gt;See &lt;a href='/blog/2010/06/23/iphone-app-part-1.html'&gt;Part 1&lt;/a&gt;, &lt;a href='/blog/2010/06/27/iphone-app-part-2.html'&gt;Part 2&lt;/a&gt;, and &lt;a href='/blog/2010/06/29/iphone-app-part-3.html'&gt;Part 3&lt;/a&gt; first&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The past week was spent trying to understand the best way to expand my application&amp;#8217;s features without have a ton of duplicated code or UI. It was also a learning experience on Core Data. Thankfully, &lt;a href='http://www.stackoverflow.com'&gt;Stackoverflow&lt;/a&gt; and its amazing contributers were very helpful.&lt;/p&gt;

&lt;h2 id='core_data_blunders'&gt;Core Data Blunders&lt;/h2&gt;

&lt;p&gt;It started as I made my first foray into implementing the search screen (i.e. the home screen of my app):&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_homescreen.jpg' alt='Home Screen' /&gt;&lt;/p&gt;

&lt;p&gt;Three of the searches (most recent wines, wines by rating, and all wines) end up doing the same thing more or less: Query for some data, sort it a certain way, and show it in a &lt;code&gt;UITableView&lt;/code&gt;. I ended up creating a custom table cell view and I wanted all three to use it:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_custom_cell.jpg' alt='Custom Cell' /&gt;&lt;/p&gt;

&lt;p&gt;Access to Core Data-provided entities is done through objects of the class &lt;code&gt;NSFetchedResultsController&lt;/code&gt;, which takes what amounts to a database query and provides many ways of accessing the results, including caching, callbacks, and iteration. When using a table view, you typically have your view controller handle callbacks for this class, which allows the table to update itself when items are added, removes, or changed. All of this boilerplate is given to you at the start of the project. So far so good.&lt;/p&gt;

&lt;p&gt;My plan was to create additional &lt;code&gt;NSFetchedResultsController&lt;/code&gt; instances inside my table view controller class and then switch between them. A fine idea that lead that numerous random difficult-to-reproduce crashes.&lt;/p&gt;

&lt;p&gt;It turns out the basic idea of what I was doing was good, but my implementation exposed a sore lack of understanding of how all this stuff fit together. I&amp;#8217;m still not sure I fully grasp it (and wish the book I bought had a bit of a deeper dive into Core Data), but after some more reasoning, I got around it. Essentially, leaving the unused &lt;code&gt;NSFetchedResultsController&lt;/code&gt; instances connected to my table view &lt;em&gt;and&lt;/em&gt; having caching turned on &lt;em&gt;and&lt;/em&gt; not properly reloading data when switching searches created a situation where they were all pretty confused about the underlying state of the database.&lt;/p&gt;

&lt;p&gt;With some judicious management of these instances, as well as disabling caching, I now have a fully-functional &amp;#8220;Recent Wines&amp;#8221;, &amp;#8220;Wines By Rating&amp;#8221; and fancy indexed &amp;#8220;All Wines&amp;#8221; view (index meaning I can jump to wines by letter, a la the Contacts application).&lt;/p&gt;

&lt;p&gt;Unfortunately, the result of turning off caching is that it takes a noticable blip of time to summon any of these views. I may just come full circle and end up with three different &lt;code&gt;UITableViewController&lt;/code&gt; instances and NIBs just so I can leave Caching on.&lt;/p&gt;

&lt;h2 id='user_experience'&gt;User Experience&lt;/h2&gt;

&lt;p&gt;Once I had gotten back to a stable app, I loaded it up on my phone and headed into the field. A few nights ago, Amy and I ended up at one of our favorite restaurants/wine bars in DC, &lt;a href='http://www.proofdc.com'&gt;Proof&lt;/a&gt;. We&amp;#8217;ve been there several times, and many of their wines-by-the-glass are in the Wine Brain. While they rotate their selections, I was curious as to what I&amp;#8217;d had there previously. Unfortunately, I had yet to implement the search-by-location feature :) Combing through the &amp;#8220;All Wines&amp;#8221; view was a bit frustrating. This made obvious several features that are now on the top of my list (some planned previously, some not):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find wines by location&lt;/li&gt;

&lt;li&gt;Actually &lt;em&gt;entering&lt;/em&gt; the location at which I had a wine&lt;/li&gt;

&lt;li&gt;Location-aware assistance of location (e.g. &amp;#8220;Are you at Proof? Here&amp;#8217;s what you&amp;#8217;ve had there&amp;#8230;&amp;#8221;)&lt;/li&gt;

&lt;li&gt;Ability to text-search the &amp;#8220;all wines&amp;#8221; list&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The good news is that my cursory reading of my book and the API docs indicates that these things are going to be &lt;em&gt;very&lt;/em&gt; easy to implement.&lt;/p&gt;

&lt;h2 id='objectivec'&gt;Objective-C&lt;/h2&gt;

&lt;p&gt;There&amp;#8217;s a lot to like about Objective-C, and a lot to dislike. Even though the handling of multiple arguments is a bit strange, I find it actually results in fairly readable code. It feels very Apple; different, but usable. Even though it&amp;#8217;s a lot to type out something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NSString *stripped = [canonicalName stringByTrimmingCharactersInSet:
                       [NSCharacterSet whitespaceAndNewlineCharacterSet]];&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It &lt;em&gt;is&lt;/em&gt; pretty readable, regardless of what programming language you are coming from. That being said, stack traces and error messages on crashes are nigh-useless, and the overall testability of iPhone apps is pretty behind the times. This months &lt;a href='http://pragprog.com/magazines'&gt;issue of Prag Prog&amp;#8217;s magazine&lt;/a&gt; has an interesting article on &lt;a href='http://github.com/unboxed/icuke'&gt;iCuke&lt;/a&gt;, which I look forward to trying out. I&amp;#8217;ve resulted to keeping a text file of test cases that I have to manually run through to make sure I haven&amp;#8217;t broken anything, and it feels, well, 1997. The rumours of a Apple&amp;#8217;s switch to Ruby are too good to be true, but one can always dream.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Continued in &lt;a href='/blog/2010/07/18/iphone-app-part-5.html'&gt;Part 5&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>My first iPhone App - Part 3</title>
   <link href="http://www.naildrivin5.com/blog/2010/06/29/iphone-app-part-3.html"/>
   <updated>2010-06-29T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/06/29/iphone-app-part-3</id>
   <content type="html">&lt;p&gt;&lt;em&gt;See &lt;a href='/blog/2010/06/27/iphone-app-part-2.html'&gt;Part 1&lt;/a&gt; and &lt;a href='/blog/2010/06/27/iphone-app-part-2.html'&gt;Part 2&lt;/a&gt; first&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Just a quick update for tonight. I&amp;#8217;m starting to get the hang of how the user interface elements I create in Interface Builder get hooked up and become available in code. It&amp;#8217;s a bit odd and not terribly intuitive, but it&amp;#8217;s starting to make a &lt;em&gt;bit&lt;/em&gt; more sense. Under the covers there&amp;#8217;s some sort of dependency injection going on (even if Apple doesn&amp;#8217;t call it that) that smells of Spring-style magic; objects get created for me and populated if I do the right thing.&lt;/p&gt;

&lt;p&gt;At any rate, I decided that, before making any more changes, I needed to get a reasonable data set into the app. I spent two painful hours exporting my Google Doc Wine Brain into CSV and parsing it with Objective-C, mapping it to my Core Data model objects. In the end, I was successful, but, WOW, what a pain compared to Ruby or Perl.&lt;/p&gt;

&lt;p&gt;Seeing this large set of data on the home screen was very motivational to start working on a drill-down/search interface, as you can see here:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_all_wines.jpg' alt='All Wines List' /&gt;&lt;/p&gt;

&lt;p&gt;Before delving into my new homescreen, I decided to work up a better color scheme that was more &amp;#8220;wine-like&amp;#8221;. I&amp;#8217;m not a big fan of apps that have fancy graphics and obscure the idiomatic iPhone UI, but a bit of a color splash would go a long way (and, not to mention, be well within my graphic design skill level). In addition, more user testing (via Amy once again) revealed that the rating control needed a much starker contrast between the selected and unselected choices. There isn&amp;#8217;t much I have control over via the API for this, so I chose an alternate style of &lt;code&gt;UISegmentedControl&lt;/code&gt; that used the &amp;#8220;iPhone blue&amp;#8221; for the selected state. I think it works OK with the color scheme, though I&amp;#8217;d prefer the &amp;#8220;merlot red&amp;#8221; that I chose for the nav bar and wine type:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_new_wine_4.jpg' alt='Colorrific New Wine Screen' /&gt;&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m starting to think that my desire to have wine entry confined to one screen might not pan out. The &amp;#8220;slot-machine&amp;#8221; control will become more and more unusable as more varietals are added, and there&amp;#8217;s really no way to even &lt;em&gt;add&lt;/em&gt; a new varietal here. I think I may have to go with the drill-down method where by I push another table view onto the stack to select (and possibly add) a varietal. For another day.&lt;/p&gt;

&lt;p&gt;Lastly, I took a stab at a better home screen:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_homescreen.jpg' alt='Home Screen' /&gt;&lt;/p&gt;

&lt;p&gt;This pretty-well represents the ways I &lt;em&gt;think&lt;/em&gt; I&amp;#8217;d want to navigate the data. Time will tell once I implement these searches, but this seems like a reasonable start.&lt;/p&gt;

&lt;p&gt;I also have to say that, despite Objective-C&amp;#8217;s overall wackiness, it was pretty easy to put this together and have the &amp;#8220;Add New Wine&amp;#8221; button bring up the &amp;#8220;Add Wine&amp;#8221; screen and to have the &amp;#8220;All Wines&amp;#8221; button navigate to the old home screen. Apple has done a reasonable job of making it easy to make an idiomatic, normal-looking iPhone app.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Continued in &lt;a href='/blog/2010/07/08/iphone-app-part-4.html'&gt;Part 4&lt;/a&gt;, and &lt;a href='/blog/2010/07/18/iphone-app-part-5.html'&gt;Part 5&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>My first iPhone App - Part 2</title>
   <link href="http://www.naildrivin5.com/blog/2010/06/27/iphone-app-part-2.html"/>
   <updated>2010-06-27T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/06/27/iphone-app-part-2</id>
   <content type="html">&lt;p&gt;&lt;em&gt;See &lt;a href='/blog/2010/06/23/iphone-app-part-1.html'&gt;Part 1&lt;/a&gt; first&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For the past several days I&amp;#8217;ve had the app on my phone and used it to enter in wines to see how the UI was working. Yesterday, I integrated Core Data (Apple&amp;#8217;s Object/Relational Mapper (ORM), for lack of a better description) so that I could actually &lt;em&gt;save&lt;/em&gt; some data. I discovered some nuances to using Core Data, as well as a refinement in the UI.&lt;/p&gt;

&lt;h2 id='ui'&gt;UI&lt;/h2&gt;

&lt;p&gt;Last night, I had both my girlfriend Amy and my good friend Clay (who is also reasonably into wine) play around with the &amp;#8220;new wine&amp;#8221; screen. Neither have an iPhone, and there were a few obvious problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They were very unaccustomed to the &amp;#8220;Done&amp;#8221; button being in the upper-right corner, as well as the &amp;#8220;slot-machine&amp;#8221; control&lt;/li&gt;

&lt;li&gt;Both had trouble with the &amp;#8220;Wine Name&amp;#8221; concept&lt;/li&gt;

&lt;li&gt;Both had trouble dismissing the keyboard&lt;/li&gt;

&lt;li&gt;Clay thought he was entering search terms and not a new Wine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Later that evening, I had a glass of wine at a bar and entered it into my app. Up until this point, I was just typing in wines I knew about, so this was the first &amp;#8220;real use&amp;#8221; of the app in the field. I quickly realized that the &amp;#8220;Wine Name&amp;#8221; concept, while important, was too vague and confusing to be the first field you enter. Most wines are known by the vineyard and some don&amp;#8217;t even have proper names or appellations. So, I swapped the fields and added some examples in the placeholder text:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_new_wine_comparison.jpg' alt='Comparison' /&gt;&lt;/p&gt;

&lt;p&gt;I also added a title to indicate that this screen is for adding a new wine. Finally, I used the &lt;a href='http://stackoverflow.com/questions/804563/how-to-hide-the-keyboard-when-empty-area-is-touched-on-iphone'&gt;background button trick&lt;/a&gt; along with some events on the rating and type controls to dismiss the keyboard if you tap anywhere outside of a text field.&lt;/p&gt;

&lt;p&gt;This feels much cleaner and flows a bit better. While varietal is probably the third most important thing (at least for New World wines), the slot-machine control would be awkwardly placed right below the vineyard/vintage text fields, so I left it where it was.&lt;/p&gt;

&lt;p&gt;As to Clay and Amy&amp;#8217;s confusion over some idiomatic iPhone design choices, I&amp;#8217;m not worrying about them a whole lot; a typical iPhone user will understand what&amp;#8217;s going on (I hope :).&lt;/p&gt;

&lt;h2 id='core_data'&gt;Core Data&lt;/h2&gt;

&lt;p&gt;Backing all this is Apple&amp;#8217;s Core Data, which grew out of the &lt;a href='http://en.wikipedia.org/wiki/Enterprise_Objects_Framework'&gt;Enterprise Objects Framework&lt;/a&gt; (and was, incidentally, my first exposure to an ORM way back in 1998), is the simplest and most idiomatic way to store and manage data on the iPhone. As with Interface Builder, you create the model visually, using a simplistic data modelling tool. I set up the bare bones of my data model and generated the classes.&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_data_model.jpg' alt='Data Model' /&gt;&lt;/p&gt;

&lt;p&gt;The first problem I ran into was in changing the model after the database had been created on the device. Core Data doesn&amp;#8217;t migrate your model for you by default. I ended up starting over with a &amp;#8220;versioned&amp;#8221; model and implementing their default migration. This will probably work for simple changes, but for more complex changes, it looks like it&amp;#8217;s somewhat difficult to migrate the model. An unfortunate reason to do some Big Design Up Front.&lt;/p&gt;

&lt;p&gt;My next problem was initializing reference data. In my case, I wanted the list of varietals as well as the list of wine types (e.g. &amp;#8220;red&amp;#8221;, &amp;#8220;white&amp;#8221;) to be in the database and managed by Core Data. I ended up creating an array of the values inside the app and then checking the database for their existence, adding them if they were missing. It&amp;#8217;s a bit cheesy, but I can extract the lists to plist files later. It &lt;em&gt;did&lt;/em&gt; give me a chance to play with Objective-C&amp;#8217;s blocks feature. I needed to map my list of &lt;code&gt;Varietal&lt;/code&gt; objects to a list of strings, so I could compare that list against my default list. While &lt;code&gt;NSArray&lt;/code&gt; doesn&amp;#8217;t provide a map function, it does provide the equivalent of Ruby&amp;#8217;s &lt;code&gt;each&lt;/code&gt; or Scala&amp;#8217;s &lt;code&gt;foreach&lt;/code&gt;. In true Apple/Objective-C style, it&amp;#8217;s called &lt;code&gt;enumerateObjectsUsingBlock&lt;/code&gt; :)&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='n'&gt;NSMutableArray&lt;/span&gt; &lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='n'&gt;strings&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;NSMutableArray&lt;/span&gt; &lt;span class='nl'&gt;arrayWithCapacity:&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;array&lt;/span&gt; &lt;span class='n'&gt;count&lt;/span&gt;&lt;span class='p'&gt;]];&lt;/span&gt;
&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;array&lt;/span&gt; &lt;span class='nl'&gt;enumerateObjectsUsingBlock:&lt;/span&gt;&lt;span class='o'&gt;^&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kt'&gt;id&lt;/span&gt; &lt;span class='n'&gt;obj&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;NSUInteger&lt;/span&gt; &lt;span class='n'&gt;i&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='kt'&gt;BOOL&lt;/span&gt; &lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='n'&gt;stop&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;strings&lt;/span&gt; &lt;span class='nl'&gt;addObject:&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;obj&lt;/span&gt; &lt;span class='nl'&gt;valueForKey:&lt;/span&gt;&lt;span class='s'&gt;@&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;]];&lt;/span&gt;
&lt;span class='p'&gt;}];&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;stop&lt;/code&gt; pointer is an out-only variable that you set to YES to allow for an early exit from the loop. I&amp;#8217;m glad they&amp;#8217;ve adopted this functional style; I forsee explicit loops becoming just as quaint as GOTOs in the near future.&lt;/p&gt;

&lt;p&gt;One thing bugged me about this process, however. I had these generated classes and it wasn&amp;#8217;t clear how to add my own methods to them without losing the code every time I re-generated my model. Enter &lt;a href='http://github.com/rentzsch/mogenerator'&gt;mogenerator&lt;/a&gt;. This provides a more sophisticated bit of code generation, givng you two classes for each model: one for machines (i.e. for Core Data to manage) and a subclass for people (to which I can add custom methods). Perfect! I wasn&amp;#8217;t able to incorporate it into XCode, but I&amp;#8217;m happy running in on the command line as needed for now.&lt;/p&gt;

&lt;h2 id='random_bits'&gt;Random Bits&lt;/h2&gt;

&lt;p&gt;I spent more time than I would&amp;#8217;ve liked tracking down a nasty bug where every attempt to convert a string to a number (for the wine vintage year) resulted in a &lt;code&gt;nil&lt;/code&gt; number. It turns out I was confused about when some object lifecycle methods were being called and my pointer to an &lt;code&gt;NSNumberFormatter&lt;/code&gt; was, in fact, pointing to &lt;code&gt;nil&lt;/code&gt;. Unlike Java, where you&amp;#8217;d get a &lt;code&gt;NullPointerException&lt;/code&gt;, or C, where you&amp;#8217;d get a core dump, it seems Objective-C just returns &lt;code&gt;nil&lt;/code&gt; and doesn&amp;#8217;t even issue a warning. Very strange. Once I realized that, the solution was obvious.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m still not 100% sure I&amp;#8217;m structuring my code properly, but Stack Overflow&amp;#8217;s stalwart iPhone SDK answerers have been &lt;em&gt;incredibly&lt;/em&gt; helpful in pointing me in the right direction.&lt;/p&gt;

&lt;h2 id='next_steps'&gt;Next Steps&lt;/h2&gt;

&lt;p&gt;Now that I&amp;#8217;ve got the ability to save and retrieve data, the next step is to start looking to browsing, viewing, and editing the database. I think the domain is restricted enough that I can use the iPhone&amp;#8217;s idiomatic drill-down table navigation to filter the database.&lt;/p&gt;

&lt;p&gt;Continued in &lt;a href='/blog/2010/06/29/iphone-app-part-3.html'&gt;Part 3&lt;/a&gt;, &lt;a href='/blog/2010/07/08/iphone-app-part-4.html'&gt;Part 4&lt;/a&gt;, and &lt;a href='/blog/2010/07/18/iphone-app-part-5.html'&gt;Part 5&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>My first iPhone App - Part 1</title>
   <link href="http://www.naildrivin5.com/blog/2010/06/23/iphone-app-part-1.html"/>
   <updated>2010-06-23T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/06/23/iphone-app-part-1</id>
   <content type="html">&lt;h2 id='background'&gt;Background&lt;/h2&gt;

&lt;p&gt;Last year, I spent most of my free time becoming familiar with Ruby, Rails, and Scala. I&amp;#8217;m by no means an expert, but I&amp;#8217;m trying to follow the advice of the &lt;a href='http://www.pragprog.com'&gt;Pragmatic Programmers&lt;/a&gt; and learn a new language/system every year. This year, it&amp;#8217;s going to be the iPhone API and Objective-C. I coded some WebObjects applications in Objective-C many years ago, so the language isn&amp;#8217;t totally unfamiliar, but the iPhone SDK, obviously, is. After working my way through the first several chapters of the &lt;a href='http://pragprog.com/titles/amiphd/iphone-sdk-development'&gt;Dudney and Adamson&amp;#8217;s &amp;#8220;iPhone SDK Development&amp;#8221;&lt;/a&gt; book, I decided I was ready to try my first real app.&lt;/p&gt;

&lt;h2 id='first_app'&gt;First App&lt;/h2&gt;

&lt;p&gt;My girlfriend and I enjoy wine, but are largely novices. On a trip to Napa we started writing down the wines we&amp;#8217;d tried and keeping personal ratings of them. The idea being twofold: try to remember good wines/avoid bad ones, and try to hone in on what our tastes are. There are so many wines and so many flavors and smells, it&amp;#8217;s just impossible to keep in your head. So, I created a Google Spreadsheet and a form to allow us to enter wines on the go, via our smart phones. The Goolge Docs form is less than usable, and this seems like the perfect job for a native iPhone app.&lt;/p&gt;

&lt;h3 id='user_experience'&gt;User Experience&lt;/h3&gt;

&lt;p&gt;Aside from learning the ins and outs of the SDK, another main goal is focus on making a highly-usable application (at least for myself and my girlfriend). So, before diving into Core Data and modelling the domain, my first version of the applicaton simply presents the &amp;#8220;add a new wine&amp;#8221; screen. This will be the screen I spend the most time in, and it&amp;#8217;s important to make it fast and easy.&lt;/p&gt;

&lt;p&gt;The Google Spreadsheet currently collects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wine Name&lt;/li&gt;

&lt;li&gt;Vineyard&lt;/li&gt;

&lt;li&gt;Vintage (year)&lt;/li&gt;

&lt;li&gt;Varietal&lt;/li&gt;

&lt;li&gt;Type (e.g. red/white)&lt;/li&gt;

&lt;li&gt;Where we had&lt;/li&gt;

&lt;li&gt;When we had&lt;/li&gt;

&lt;li&gt;My rating&lt;/li&gt;

&lt;li&gt;Her rating&lt;/li&gt;

&lt;li&gt;Tasting Notes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That&amp;#8217;s obviously too much for one iphone screen, and, if I&amp;#8217;m entering something in a hurry, I might not have time to go through all that. Further, I think adding multiple ratings makes things a bit confusing, so I focussed my screen on the identifying characteristics (name/vineyard/vintage), the rating, and the type:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_new_wine_1.jpg' alt='First Attempt' /&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I tried to fit the &amp;#8220;where&amp;#8221; on the bottom, as well as a &amp;#8220;enter more information&amp;#8221; button. After loading this on the phone, it was just not working out, plus I was missing the varietal, which is fairly important (at least to me).&lt;/p&gt;

&lt;p&gt;My next attempt simply ignores the &amp;#8220;add more&amp;#8221; concept, and, by using the segmented control, I was able to fit the type into a more compact area, while including the varietal as a &amp;#8220;slot-machine&amp;#8221;/picker.&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/wine_brain_new_wine_2.jpg' alt='Second Attempt' /&gt;&lt;/p&gt;

&lt;p&gt;My plan is to load this onto the phone and try using it the next few times I&amp;#8217;m out. I figure I can do without the tasting notes or location if it keeps the UI simple&lt;/p&gt;

&lt;h3 id='the_code'&gt;The Code&lt;/h3&gt;

&lt;p&gt;Objective-C and XCode are a whole different world from Java or Ruby. First thing that bit me is the memory management. I was familiar with the rules (or so I thought). Basically, if you call a method like &amp;#8220;copyXXX&amp;#8221; or &amp;#8220;initXXX&amp;#8221; to create a new object, you must &lt;code&gt;release&lt;/code&gt; it when you are done with it. If you get access to an object through any other means, you should &lt;em&gt;not&lt;/em&gt; release it.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='c1'&gt;// my class has an NSArray called varietals that I&amp;#39;m initializing here&lt;/span&gt;
&lt;span class='n'&gt;varietals&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;NSArray&lt;/span&gt; &lt;span class='nl'&gt;arrayWithObjects:&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Barbera&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Cabernet Franc&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='c1'&gt;// snip&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Zinfandel&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Other&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='nb'&gt;nil&lt;/span&gt;&lt;span class='p'&gt;];&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since I&amp;#8217;m &lt;em&gt;not&lt;/em&gt; calling an &amp;#8220;init&amp;#8221; style method, I figured I didn&amp;#8217;t need to release it in &lt;code&gt;dealloc&lt;/code&gt;. For some reason, this made me decide that I didn&amp;#8217;t need to &lt;code&gt;retain&lt;/code&gt; it. This caused my first crash and trip through the debugger to figure out what in the heck is going on.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='c1'&gt;// my class has an NSArray called varietals that I&amp;#39;m initializing here&lt;/span&gt;
&lt;span class='n'&gt;varietals&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;[[&lt;/span&gt;&lt;span class='n'&gt;NSArray&lt;/span&gt; &lt;span class='nl'&gt;arrayWithObjects:&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Barbera&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Cabernet Franc&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='c1'&gt;// snip&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Zinfandel&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='s'&gt;@&amp;quot;Other&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                  &lt;span class='nb'&gt;nil&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='n'&gt;retain&lt;/span&gt;&lt;span class='p'&gt;];&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since I needed &lt;code&gt;varietals&lt;/code&gt; to survive the method where I was initializing it, I had to &lt;code&gt;retain&lt;/code&gt; it.&lt;/p&gt;

&lt;h3 id='other_struggles'&gt;Other struggles&lt;/h3&gt;

&lt;p&gt;Interestingly, laying out the UI and getting that hooked up isn&amp;#8217;t too bad; the thing I&amp;#8217;m having the most trouble with is figuring out what is the &amp;#8220;unsurprising&amp;#8221; way of doing things; tutorial code from books is rarely very well written; it&amp;#8217;s usually done in a certain way to make concepts clear, but I haven&amp;#8217;t yet found a definitive &amp;#8220;here&amp;#8217;s how you organize your code&amp;#8221; or &amp;#8220;iPhone best practices&amp;#8221; that seems relatively comprehensive.&lt;/p&gt;

&lt;p&gt;At any rate, I figure if I can get the UX to be reasonably good, the rest should sort itself out.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll continue posting about my progress here on my blog. If I can get the app polished and working, my girlfriend might demand and Android version. Would be interesting to compare the two paradigms (especially since Android is all Java, which has been my bread-and-butter for many years).&lt;/p&gt;

&lt;p&gt;&lt;a href='/blog/2010/06/27/iphone-app-part-2.html'&gt;Continued in Part 2&lt;/a&gt;, &lt;a href='/blog/2010/06/29/iphone-app-part-3.html'&gt;Part 3&lt;/a&gt;, &lt;a href='/blog/2010/07/08/iphone-app-part-4.html'&gt;Part 4&lt;/a&gt;, and &lt;a href='/blog/2010/07/18/iphone-app-part-5.html'&gt;Part 5&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>In defense of vi</title>
   <link href="http://www.naildrivin5.com/blog/2010/06/14/in-defense-of-vi.html"/>
   <updated>2010-06-14T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/06/14/in-defense-of-vi</id>
   <content type="html">&lt;p&gt;Sadly, I was unable to attend &lt;a href='http://www.railsconf.org'&gt;RailsConf&lt;/a&gt; this year. It was in Baltimore, and it would&amp;#8217;ve been a lot of fun, but it just wasn&amp;#8217;t in the cards. One of the great things about RailsConf is that the videos are posted online very quickly and are always of high quality. While I always like hearing &lt;a href='http://www.youtube.com/watch?v=b0iKYRKtAsA'&gt;DHH&lt;/a&gt; speak, I try to never miss one of &lt;a href='http://www.twitter.com/unclebobmartin'&gt;Uncle Bob Martin&lt;/a&gt;, author of the must-go-read-this-right-now &lt;a href='http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1276567370&amp;amp;sr=8-1'&gt;Clean Code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This year, he gave an &lt;a href='http://www.youtube.com/watch?v=mslMLp5bQD0'&gt;awesome talk&lt;/a&gt; on the (lack of) innovation in software development. He pointed out that we were still writing the same type of code now as we were 40 years ago. In one part, he asks the crowd what editor they use (knowing full well most will say &lt;a href='http://www.vim.org'&gt;vim&lt;/a&gt;). He then proceeds to make light of the audience for using a 19-year-old editor based on a 34-year-old editor. While his criticism is brief, I think it speaks more to the sorry state of text editing than to the developers (like me) who are &amp;#8220;still&amp;#8221; using vim.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m sure that unclebob is one of the more advanced IDE users, but it just &lt;em&gt;pains&lt;/em&gt; me watching my co-workers meander through their code, selecting things with the mouse, and deleting long swaths of text by just hitting the delete key a lot.&lt;/p&gt;

&lt;p&gt;While an IDE is great for learning a new environment (especially one as pedantic and verbose as Java or Objective-C), the editing capabilities are counter-intuitive and degenerate. vim may be hard on the newbie, but it&amp;#8217;s intuitive and logical. When you understand the &amp;#8220;zen&amp;#8221; of vim, you can fly through your code, playing it like a musical instrument. It &lt;em&gt;affords&lt;/em&gt; muscle memory and allows sophisticated chaining of movement, intent, and action. You can &lt;em&gt;see&lt;/em&gt; what you want to accomplish and your hands make it so, all without reaching for a mouse, cursoring, using the delete key, or contorting your hand with some awful combination of key modifiers.&lt;/p&gt;

&lt;p&gt;Think of it as a piano; it&amp;#8217;s a very simple base of simple sounds and actions that, when chained together, can be used to make beautiful music. An IDE is more like a fancy Casio keyboard with built-in songs and beats. Shiny, but hollow.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Are private methods code smells?</title>
   <link href="http://www.naildrivin5.com/blog/2010/05/26/is-private-a-code-smell.html"/>
   <updated>2010-05-26T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/05/26/is-private-a-code-smell</id>
   <content type="html">&lt;p&gt;Having had discussions with co-workers on the utility of private methods and &lt;a href='http://scala-programming-language.1934581.n4.nabble.com/Just-curious-why-public-as-default-visibility-td2228941.html'&gt;recently on the scala mailing list&lt;/a&gt;, there&amp;#8217;s been the notion that private methods (or even protected methods) are code smells &amp;#8211; indicators that there is something wrong with the design of your code. I believe in many cases they can be, but that private (and protected) methods still have their uses, especially in maintaining a clean design under constraints of getting things done. First, we need to know what we are talking about.&lt;/p&gt;

&lt;h2 id='definitions'&gt;Definitions&lt;/h2&gt;

&lt;p&gt;While the technical meaning of access modifiers varies with the language, the &lt;em&gt;intent&lt;/em&gt; these concepts communicate is what we&amp;#8217;re talking about here. I assert that the &lt;em&gt;intent&lt;/em&gt; of public/protected/private is (and/or should be) as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;public&lt;/em&gt; - this method is part of the published API and will not change within major versions of the class&lt;/li&gt;

&lt;li&gt;&lt;em&gt;protected&lt;/em&gt; - this method is a hook for modifying the behavior of this class using subclasses. It, too, will not change within major versions of the class (of course, it also might exist for code-reuse internal to the class hierarchy).&lt;/li&gt;

&lt;li&gt;&lt;em&gt;private&lt;/em&gt; - this method was &lt;em&gt;refactored out of a well tested public or protected method&lt;/em&gt; for reasons of clarity or internal re-use. This method may absolutely change, even in patch releases, and should not be relied upon to even exist&lt;/li&gt;

&lt;li&gt;&lt;em&gt;package private&lt;/em&gt; (bonus for Java) - this method was written by someone lazy or ingorant, &lt;em&gt;or&lt;/em&gt; by someone who acknowledges that this code should be pulled out into its own class, but hasn&amp;#8217;t done so, yet still wants to test it seperately, thus breaking encapsulation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='why_would_private_methods_be_code_smells'&gt;Why would private methods be code smells?&lt;/h2&gt;

&lt;p&gt;The most concise argument is that private methods could indicate that the class that contains them is doing too many things. Consider this code from shorty, my URL shortener:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='k'&gt;override&lt;/span&gt; &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;contextInitialized&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;ServletContextEvent&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getServletContext&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;log&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Initializing our hasher/DB&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;dirName&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getServletContext&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getInitParameter&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;
    &lt;span class='nc'&gt;ShortyServlet&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;DB_DIR_PARAM&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dirName&lt;/span&gt; &lt;span class='o'&gt;!=&lt;/span&gt; &lt;span class='kc'&gt;null&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;dir&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;File&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dirName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;exists&lt;/span&gt;&lt;span class='o'&gt;())&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
      &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;isDirectory&lt;/span&gt;&lt;span class='o'&gt;())&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;hasher&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='nc'&gt;URIHasher&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nc'&gt;DB&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;))&lt;/span&gt;
        &lt;span class='n'&gt;hasher&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;start&lt;/span&gt;
        &lt;span class='n'&gt;uriHasher&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='n'&gt;hasher&lt;/span&gt;
        &lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getServletContext&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;setAttribute&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;
          &lt;span class='nc'&gt;ShortyServlet&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;URI_HASHER_ATTRIBUTE&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt;&lt;span class='n'&gt;uriHasher&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
      &lt;span class='o'&gt;}&lt;/span&gt;
      &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;throw&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;ServletException&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getAbsolutePath&lt;/span&gt; 
          &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s'&gt;&amp;quot; is not a directory&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
      &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
      &lt;span class='k'&gt;throw&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;ServletException&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getAbsolutePath&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s'&gt;&amp;quot; doesn&amp;#39;t exist&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
  &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;throw&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;ServletException&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;You must supply a value for &amp;quot;&lt;/span&gt; 
      &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='nc'&gt;ShortyServlet&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;DB_DIR_PARAM&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Is it totally clear what this method does? If not, it basically checks that the directory configured for our database exists and is a directory, giving us a specific error message if not. It&amp;#8217;s a bit long and full of error checking, so the meat where it creates our URI hasher and gives it to the servlet is somewhat obscured. Here&amp;#8217;s a cleaned up version:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='k'&gt;override&lt;/span&gt; &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;contextInitialized&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;ServletContextEvent&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getServletContext&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;log&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Initializing our hasher/DB&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='n'&gt;getDBDir&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;match&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;case&lt;/span&gt; &lt;span class='nc'&gt;Right&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
      &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;hasher&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='nc'&gt;URIHasher&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nc'&gt;DB&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;))&lt;/span&gt;
      &lt;span class='n'&gt;hasher&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;start&lt;/span&gt;
      &lt;span class='n'&gt;uriHasher&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='n'&gt;hasher&lt;/span&gt;
      &lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getServletContext&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;setAttribute&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;
        &lt;span class='nc'&gt;ShortyServlet&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;URI_HASHER_ATTRIBUTE&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt;&lt;span class='n'&gt;uriHasher&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;case&lt;/span&gt; &lt;span class='nc'&gt;Left&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;errorMessage&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; 
      &lt;span class='k'&gt;throw&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;ServletException&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;errorMessage&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;

&lt;span class='k'&gt;private&lt;/span&gt; &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;getDBDir&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='k'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;ServletContextEvent&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;dirName&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getServletContext&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getInitParameter&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;
    &lt;span class='nc'&gt;ShortyServlet&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;DB_DIR_PARAM&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dirName&lt;/span&gt; &lt;span class='o'&gt;!=&lt;/span&gt; &lt;span class='kc'&gt;null&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;val&lt;/span&gt; &lt;span class='n'&gt;dir&lt;/span&gt; &lt;span class='k'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nc'&gt;File&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dirName&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;exists&lt;/span&gt;&lt;span class='o'&gt;())&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
      &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;isDirectory&lt;/span&gt;&lt;span class='o'&gt;())&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
        &lt;span class='nc'&gt;Right&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
      &lt;span class='o'&gt;}&lt;/span&gt;
      &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
        &lt;span class='nc'&gt;Left&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getAbsolutePath&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s'&gt;&amp;quot; is not a directory&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
      &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
      &lt;span class='nc'&gt;Left&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;getAbsolutePath&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s'&gt;&amp;quot; doesn&amp;#39;t exist&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
  &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='nc'&gt;Left&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;You must supply a value for &amp;quot;&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='nc'&gt;ShortyServlet&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='nc'&gt;DB_DIR_PARAM&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;#8217;ve added lines of code, but our public method is a lot clearer: we get the dir for our DB; if we get a &amp;#8220;right&amp;#8221;, we have a usable dir, and if we get a &amp;#8220;left&amp;#8221; (the Scala convention for an error), we have the error message to use for our exception.&lt;/p&gt;

&lt;p&gt;So, is &lt;code&gt;getDBDir&lt;/code&gt; now a code smell? This is a private method and, this means that &lt;code&gt;contextInitialized&lt;/code&gt; was tested and we extracted the private method as step three of the TDD &amp;#8220;Test/Fix/Refactor&amp;#8221; cycle.&lt;/p&gt;

&lt;p&gt;Of course, &lt;code&gt;getDBDir&lt;/code&gt; has nothing to do with the &lt;code&gt;ServletContextListener&lt;/code&gt; and is really all about checking for a valid path. So, we should extract it to a new class, right?&lt;/p&gt;

&lt;p&gt;Well, if we &lt;em&gt;did&lt;/em&gt; do that, we&amp;#8217;ve now actually added a public API to our codebase. Unless we make the new class completely private to the enclosing class, we&amp;#8217;ve now introduced a new public class that must be tested and managed as part of our system&amp;#8217;s public API.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t see the benefit to doing that. I don&amp;#8217;t particularly &lt;em&gt;want&lt;/em&gt; this method to be in the public API (at least not &lt;em&gt;now&lt;/em&gt;). So, what about making it a private inner class? That doesn&amp;#8217;t seem to be much different than what we have now, though it might save a few minutes on a future extraction.&lt;/p&gt;

&lt;h2 id='when_is_this_a_code_smell'&gt;When IS this a code smell?&lt;/h2&gt;

&lt;p&gt;This was a simple example. Consider a class like &lt;a href='http://github.com/davetron5000/gliffy/blob/master/lib/gliffy/url.rb'&gt;&lt;code&gt;SignedUrl&lt;/code&gt; in my Gliffy Ruby client&lt;/a&gt;. This class has a fair number of private methods and, overall, is pretty large. The private methods are vague things like &lt;code&gt;handle_params&lt;/code&gt; and &lt;code&gt;get_signing_key&lt;/code&gt;. The private methods aren&amp;#8217;t really the problem, however; They are a symptom of the fact that this class is just doing too many things. A better design would be to split this class up into something like a &lt;code&gt;UrlParams&lt;/code&gt;, &lt;code&gt;UrlSigner&lt;/code&gt; and &lt;code&gt;UrlAssembler&lt;/code&gt; (just off the top of my head). The result would be more smaller classes, each with fewer public &lt;em&gt;and&lt;/em&gt; private methods.&lt;/p&gt;

&lt;h2 id='what_about_protected_methods'&gt;What about protected methods?&lt;/h2&gt;

&lt;p&gt;In Ruby, you don&amp;#8217;t see a lot of protected methods. In well-designed Java frameworks (such as &lt;a href='http://www.springframework.org'&gt;Spring&lt;/a&gt;), you&amp;#8217;ll see them as I&amp;#8217;ve described above: hooks into a helper class that allow you to customize how that class behaves via subclassing. In non-library code, protected methods tend to get used for code-reuse in narrowly-focused class hierarchies. For example, the project I&amp;#8217;m working on has a &lt;code&gt;BaseController&lt;/code&gt; that provides common methods to the actual web controllers. Having used protected methods for both of these purposes, I think that, honestly, both &lt;em&gt;can&lt;/em&gt; be code smells.&lt;/p&gt;

&lt;h3 id='protected_methods_as_hooks'&gt;Protected methods as hooks&lt;/h3&gt;

&lt;p&gt;In the case of providing &amp;#8220;hooks&amp;#8221;, I think it&amp;#8217;s clear that by providing them at all, you are acknowledging that your class &lt;em&gt;might&lt;/em&gt; be poorly designed (or that your language lacks the expressiveness to better design it). Consider the venerable (and now deprecated) &lt;a href='http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/servlet/mvc/SimpleFormController.html'&gt;&lt;code&gt;SimpleFormController&lt;/code&gt;&lt;/a&gt;, a Spring MVC class that provides &lt;em&gt;many&lt;/em&gt; protected-method hooks, one of which is &lt;code&gt;protected Map referenceData(HttpServletRequest request)&lt;/code&gt;. This is called during the lifecycle of the controller to get any data needed by the form that should be available to the view (for example, a list of U.S. states from the database). Your subclass of &lt;code&gt;SimpleFormController&lt;/code&gt; overrides this to provide the data as a map.&lt;/p&gt;

&lt;p&gt;Why not create an interface called &lt;code&gt;ServletRequestToReferenceData&lt;/code&gt; that contains this method, and inject an instance into &lt;code&gt;SimpleFormController&lt;/code&gt;? This would be very Spring-like. My guess as to why this &lt;em&gt;isn&amp;#8217;t&lt;/em&gt; the case is that there is simply too much overhead in making yet another one-method interface and the designer of &lt;code&gt;SimpleFormController&lt;/code&gt; just felt this was a reasonable tradeoff.&lt;/p&gt;

&lt;p&gt;In Scala, however, this could simply take a function:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='n'&gt;referenceData&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;A&lt;/span&gt;&lt;span class='o'&gt;]((&lt;/span&gt;&lt;span class='nc'&gt;HttpServletRequest&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='nc'&gt;Map&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;,&lt;span class='kt'&gt;A&lt;/span&gt;&lt;span class='o'&gt;]);&lt;/span&gt;

  &lt;span class='c1'&gt;// ...&lt;/span&gt;


  &lt;span class='n'&gt;controller&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;referenceData&lt;/span&gt;&lt;span class='o'&gt;{&lt;/span&gt; &lt;span class='n'&gt;request&lt;/span&gt; &lt;span class='k'&gt;=&amp;gt;&lt;/span&gt; 
    &lt;span class='c1'&gt;// create our map based on the request&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In Ruby, the overhead of creating a new class isn&amp;#8217;t nearly as onerous, and we could still inject a block as we do in Scala.&lt;/p&gt;

&lt;p&gt;Ultimately, I would say that you have to make a tradeoff here, and it &lt;em&gt;has&lt;/em&gt; to take the language and frameworks into account; a class with many, many hooks might be a code smell, but using it as a means to avoid language ceremony in the name of OO purity is probably a reasonable design tradeoff.&lt;/p&gt;

&lt;h3 id='protected_methods_as_code_sharing'&gt;Protected methods as code sharing&lt;/h3&gt;

&lt;p&gt;This use of protected methods is harder to justify, but incredibly handy. Still, this could be another case of Java (e.g.) not providing the necessary language features to make class extraction more straightforward. As mentioned, in my current application, I have a &lt;code&gt;BaseController&lt;/code&gt;. It has a helper method as follows:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='kd'&gt;protected&lt;/span&gt; &lt;span class='n'&gt;Person&lt;/span&gt; &lt;span class='nf'&gt;getAndValidateLoggedInPerson&lt;/span&gt;&lt;span class='o'&gt;()&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;Person&lt;/span&gt; &lt;span class='n'&gt;p&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;personService&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;getPerson&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;
    &lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;authenticationService&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;loggedInUserId&lt;/span&gt;&lt;span class='o'&gt;());&lt;/span&gt;
  &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;p&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='kc'&gt;null&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;throw&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;NotFoundException&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
  &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;p&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Because of Spring MVC, we have specialized exceptions for HTTP errors, such as &amp;#8220;NOT_FOUND&amp;#8221;. Here we contain the logic to identify the id of the logged-in person as well as the check for existence. Having this available to all controllers in the entire system is very handy.&lt;/p&gt;

&lt;p&gt;But, is this a code smell?&lt;/p&gt;

&lt;p&gt;We could make a class that does this, turning this code:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='n'&gt;Person&lt;/span&gt; &lt;span class='n'&gt;p&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;getAndValidateLoggedInPerson&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;into this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='n'&gt;Person&lt;/span&gt; &lt;span class='n'&gt;p&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;personValidatorAndGetter&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;getPerson&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;creating a one method class that has many lines of injected dependeicies and other boilerpalte with a few actual lines of code.&lt;/p&gt;

&lt;p&gt;I think this is yet another case of pragmatically dealing with language ceremony. In Scala or Ruby, the overhead of creating re-usable bits of code like this is far lower than for Java; In Scala one could envision a simple function, possibly with some implicit parameters. Ultimateley, &amp;#8220;too much&amp;#8221; of this sort of thing &lt;em&gt;should&lt;/em&gt; be a code smell, but small bits of this, in the name of simplicity, clarity, and simply keeping the codebase smaller isn&amp;#8217;t an automatic red flag.&lt;/p&gt;

&lt;h2 id='conclusions'&gt;Conclusions&lt;/h2&gt;

&lt;p&gt;So, are non-public methods code smells? If we take the &lt;a href='http://en.wikipedia.org/wiki/Code_smell'&gt;wikipedia definition&lt;/a&gt;, which is clear that a code smell indicates merely the &lt;em&gt;possibility&lt;/em&gt; of deeper problems in your code, then, yes, private and protected methods &lt;em&gt;are&lt;/em&gt; code smells.&lt;/p&gt;

&lt;p&gt;But, should they be avoided at all costs? Absolutely not. There&amp;#8217;s many valid reasons to use them, and they do not deserve the blame for an ill-concieved class. Coding in the real world is about tradeoffs; we have to do the best thing we can with the time, resources, and tools at our disposal. These tradeoffs may not result in an &lt;a href='http://en.wikipedia.org/wiki/Edmond_Hoyle'&gt;According-to-Hoyle&lt;/a&gt; OO (or functional) design, but we&amp;#8217;re not writing code to provide examples of programming paradigms or design patterns; we&amp;#8217;re writing it to accomplish something and provide value. And, as professionals, we need to do it at a predictable rate that doesn&amp;#8217;t incur too much technical debt.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Video of My Talk at ScalaDays 2010</title>
   <link href="http://www.naildrivin5.com/blog/2010/04/30/my-talk-at-scala-days.html"/>
   <updated>2010-04-30T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/04/30/my-talk-at-scala-days</id>
   <content type="html">&lt;p&gt;
&lt;a href=&quot;http://days2010.scala-lang.org/node/138/169&quot;&gt;Video of my talk at ScalaDays is online&lt;/a&gt;.  Check it out.  Feedback very much appreciated!
&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;http://days2010.scala-lang.org/node/138/169&quot;&gt;&lt;img src=&quot;/images/scaladays_talk.jpg&quot; width=&quot;400&quot; border=&quot;0&quot;/&gt;&lt;/a&gt;
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Scala Days Impressions</title>
   <link href="http://www.naildrivin5.com/blog/2010/04/22/scala-days-recap.html"/>
   <updated>2010-04-22T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/04/22/scala-days-recap</id>
   <content type="html">&lt;p&gt;
I had the good fortune to not only attend &lt;a href=&quot;http://days2010.scala-lang.org/&quot;&gt;ScalaDays 2010&lt;/a&gt;, but also to speak (generously supported by &lt;a href=&quot;http://www.opower.com&quot;&gt;my employer&lt;/a&gt;).  The experience overall was great.
I talked to some really enthusiastic and interesting people (including two high school kids from Austria who were using Lift because, after three years of Java, they were tired of it already!)
&lt;/p&gt;
&lt;h1&gt;Overall Impressions&lt;/h1&gt;
&lt;ul&gt;
    &lt;li&gt;Scala 2.8 has some &lt;b&gt;really&lt;/b&gt; powerful new features; I'm almost &lt;b&gt;glad&lt;/b&gt; I don't have a significant codebase
    using 2.7, because I would hate to &lt;b&gt;not&lt;/b&gt; be able to use 2.8&lt;/li&gt;
    &lt;li&gt;The conference had a wide variety of talks, at varying skill levels; this was not a &quot;beginners-only&quot; conference, though
    there were plenty of introductory talks (e.g. the &lt;a href=&quot;http://akkasource.org/&quot;&gt;Akka&lt;/a&gt; talk).&lt;/li&gt;
    &lt;li&gt;The Scala team seems very interested in moving Scala into industry and changing the perception of it as an &quot;academic&quot;
    language (though I'm not convinced they know what to do, nor should this be their responsibility).&lt;/li&gt;
    &lt;li&gt;Most people I talked to who weren't using Scala at their jobs were looking at the strategy &lt;a href=&quot;http://sneaking-scala.heroku.com/&quot;&gt;I had employed&lt;/a&gt;
    (using it for better testing), or were just frustrated with not being able to take advantage of Scala's productivity.&lt;/li&gt;
    &lt;li&gt;Scala's flexible syntax and powerful constructs are being used for a very wide variety of things; there were talks
    on using it for &lt;a href=&quot;http://processing.org/&quot;&gt;Processing&lt;/a&gt;, parallel collections, and cross-compilation to
    non-standard architectures (i.e. chips with no JVM available).&lt;/li&gt;
    &lt;li&gt;The term &quot;monad&quot; was mentioned during exactly one talk and not at all for the rest of the conference.  This made
    me feel very good, because the impression I get on the Scala mailing list sometimes is that if you don't understand
    mathematical type theory, you are a moron who can never understand Scala.  This impression has been proved false.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Talks I Attended&lt;/h2&gt;
&lt;p&gt;
It was very interesting to compare this conference to a &lt;a href=&quot;http://www.nofluffjuststuff.com/home/main&quot;&gt;No Fluff Just Stuff&lt;/a&gt; conference.  At those, the speakers
are professional, both in that they are getting paid and that they are just, really, really good at speaking and presenting.  Their talks, however, tend to be introductory and not terribly advanced.  I think that's fine, these are the type of speakers you want to have when you need to &quot;get the message out&quot; on some new and interesting technologies.
&lt;/p&gt;
&lt;p&gt;
The speakers at ScalaDays, however, were just regular people using Scala and wanting to talk about it.  As such, things like presentation style and slides were highly varied in terms of quality.  That being said, even the speakers who had the most trouble, still had some interesting things to talk about.  Following are my quick thoughts on each of the talks I attended:
&lt;/p&gt;
&lt;h3&gt;Opening Keynote&lt;/h3&gt;
&lt;h4&gt;by Martin Odersky&lt;/h4&gt;
&lt;p&gt;
His talk was on the new features of Scala 2.8 which, as I said above, are quite exciting.  Package objects, new collections library, and default/named arguments are just some of the highlights.  All-in-all, some very exciting features.
&lt;/p&gt;
&lt;h3&gt;Runing Scala in the Browser&lt;/h3&gt;
&lt;h4&gt;by Wolfgang Kuehn&lt;/h4&gt;
&lt;p&gt;
He had created a way to write Scala code and turn it into JavaScript, much like how GWT does this with Java.  His approach wasn't geared around UI widgets, however, but in creating AJAX applications using WebSockets.  I've always felt JavaScript was assembly language (which is why I think &lt;a href=&quot;http://jashkenas.github.com/coffee-script/&quot;&gt;coffeescript&lt;/a&gt; is so interesting), and this was another way to leverage JavaScript without having to deal with it.
&lt;/p&gt;
&lt;h3&gt;Scala Parallel Collections&lt;/h3&gt;
&lt;h4&gt;by Aleksander Prokopec&lt;/h4&gt;
&lt;p&gt;
This was a preview of a Scala 2.8.1 (or later) feature, where a subpackage of the new 2.8 collections library was created that could perform the collection operations in parallel.  Consider a &lt;tt&gt;filter&lt;/tt&gt; on a collection; this is highly parallelizable.  This library is being created to basically implement that in a transparent fashion.  Really interesting stuff.  They had even considered load balancing, via some interesting work-stealing mechanisms.  In only 30 minutes, there wasn't a &lt;b&gt;huge&lt;/b&gt; amount of detail, but this seems to be another way in which parallel computation could be done very easily.
&lt;/p&gt;
&lt;h3&gt;Developing the Scala Bindings to the Fly Object Space&lt;/h3&gt;
&lt;h4&gt;by Channing Walton, Nigel Warren, Simon Kent&lt;/h4&gt;
&lt;p&gt;
The concept of &quot;object spaces&quot; never really sunk in with me, but it wasn't actually that relevant to the talk.  This was basically a comparison of a Java library and it's straight-port to Scala.  As expected, the Scala implementations were all much more succinct and (to me) clear.  The speakers hadn't used a lot of Crazy Scala Magic&amp;#8482; to achieve the real code reduction that was shown.  This talk made it very clear that even if you write &quot;Java in Scala&quot;, you still get a lot of productivity gains.
&lt;/p&gt;
&lt;h3&gt;CCSTM: Library-based STM for Scala&lt;/h3&gt;
&lt;h4&gt;by Nathan Bronson, Hassan Chafi, Kunle Olukotun&lt;/h4&gt;
&lt;p&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Software_transactional_memory&quot;&gt;Software Transactional Memory&lt;/a&gt; is one of the go-to features of Clojure.  Clojure supports it natively, while Scala does not.  This talk was on an implementation of STM as a library for Scala.  It seemed relatively simple to use and understand.  While it's not as &quot;clean&quot; as the Clojure way of doing things, the speaker made a solid case for a library implementation being a better tradeoff, given the difficulty in adding it to the language at this point in Scala's life (it's easy to forget how mature the Scala language and compiler are, despite how &quot;new&quot; it seems).
&lt;/p&gt;
&lt;h3&gt;Lightweight language support for type-based, concurrent event processing&lt;/h3&gt;
&lt;h4&gt;by Philipp Haller&lt;/h4&gt;
&lt;p&gt;
This talk proposed a function type called &quot;Translucent Functions&quot; that were better-suited to concurrency than the partial functions used in the actor library.  Honestly, it was a bit over my head, and I wasn't able to catch up with the speaker.  Perhaps the paper would be more elucidating for me.
&lt;/p&gt;
&lt;h3&gt;Data Parallel Programming in Scala&lt;/h3&gt;
&lt;h4&gt;by Bruce Lester&lt;/h4&gt;
&lt;p&gt;
This talk was very similar to the one on Scala Parallel Collections.  Here, the speaker had created a collection library separate from the Scala one, designed specifically to allow parallel processing.  He had a very different approach, using control structures to indicate areas where parallelism could occure.  It was pretty interesting, but the Scala 2.8 Collections Library implementation seemed a lot cleaner to me than this.
&lt;/p&gt;
&lt;h3&gt;Type Specialization in Scala&lt;/h3&gt;
&lt;h4&gt;by Iulian Drago&amp;#x219;&lt;/h4&gt;
&lt;p&gt;
One of the new features of 2.8 is the ability to &quot;specialize&quot; your code to work with primitive types and avoid boxing/unboxing.  This is something Java cannot really do.  This talk was an overview of how that worked and what specializations were done to the Scala library.  I guess it's nice that this kind of optimization if available, but I think it would have negligible gains for most real-world applications that weren't doing constant number crunching.  Even in that case, you don't necessarily need this.
&lt;/p&gt;
&lt;h3&gt;Leaky Monads&lt;/h3&gt;
&lt;h4&gt;by Josh Suereth&lt;/h4&gt;
&lt;p&gt;
How could I not attend the only session (and mention!) of Monads?  The speaker gave a good overview of using Monads to
implement automatic resource management (e.g. &lt;code&gt;File.open { |file| file.readlines.whatever }&lt;/code&gt;).  The idea was that since Monads are designed to hold onto the objects they manage, it's a bit inconvienient when dealing with the results of operating on managed resources.  Thus, his monads &quot;leaked&quot; their contents to create more concise code.
&lt;/p&gt;
&lt;h3&gt;Type-safe SQL embedded in Scala&lt;/h3&gt;
&lt;h4&gt;by Christoph Wulf&lt;/h4&gt;
&lt;p&gt;
Akin to &lt;a href=&quot;http://en.wikipedia.org/wiki/LINQ&quot;&gt;LINQ&lt;/a&gt;, this talk showed how to write SQL directly inside Scala code, but maintain type safety.  It uses
a compiler plugin to achieve this, and he talked a lot about how to tell the difference between embedded SQL and regular Scala code.  I guess the plugin introspects your database to get the types and generates a bunch of code using some Scala classes that get substituted in during compilation.  Pretty interesting.  I'm not sure I'm really &lt;i&gt;missing&lt;/i&gt; SQL right in my code, but it is certainly cleaner than JDBC.
&lt;/p&gt;
&lt;h3&gt;Scala at LinkedIn: Distribute Computing with Norbert&lt;/h3&gt;
&lt;h4&gt;by Chris Conrad&lt;/h4&gt;
&lt;p&gt;
This was a talk about how LinkedIn is using Scala to glue together some enabling technologies to create their social network graph.  It seemed really clean and simple, especially since the underlying technologies are all Java-based.  This was mostly an overview of the API and some usage examples.  It's &lt;a href=&quot;http://sna-projects.com/norbert/&quot;&gt;open source&lt;/a&gt;, and looks pretty interesting.  I'm not sure it would be useful for me at my job, but definitely seems like a cool project.
&lt;/p&gt;
&lt;h3&gt;Akka&lt;/h3&gt;
&lt;h4&gt;by Jonas Boner&lt;/h4&gt;
&lt;p&gt;
I was looking forward to this one quite a bit, as akka gets a lot of hype on Twitter.  I think 30 minutes was just too short, as it was pretty light on details.  There was a lot of assertions about Akka that the speakers just didn't have time to elucidate or substantiate.  I would love to see a comparison of Scala Actor vs. Akka Actor code and discuss why the Akka way is better.  Similarly, I'd love to see the basis for all the assertions on Akka's performance; it certainly gets a lot of hype.  Jonas is currently working on publicizing the production deployments of Akka (which would go a long way) as well as establishing commercial support for it (which &lt;b&gt;also&lt;/b&gt; goes a long way :).
&lt;/p&gt;
&lt;h3&gt;Scala IDE for Eclipse&lt;/h3&gt;
&lt;h4&gt;by Miles Sabin&lt;/h4&gt;
&lt;p&gt;
I went to this purely for my co-workers.  I hate IDEs in general, and Eclipse does some pretty evil things to my co-workers, yet many of them still swear by it.  At any rate, Miles was almost impossible for me to understand (despite being English!) and most of what I got out of the presentation was that Eclipse was very much designed to work with only Java, requiring some nasty hacks to get Scala working with it.  It seems Miles' Herculean efforts have been used to get around this and there now seems to be a nice development environment for extending and enhancing the Scala plugin.
&lt;/p&gt;
&lt;h3&gt;sbt Design and Implementation&lt;/h3&gt;
&lt;h4&gt;by Mark Harrah&lt;/h4&gt;
&lt;p&gt;
While sbt isn't my ideal build tool, but it's a billion times better than Maven and Mark's talk actually made me appreciate it a lot more.  He is unabashedly in favor of terse symbols over long method names, and he spent some time explaining the rational behind them (thus making things make a bit more sense). His assertion is that you will eventually internalize the symbols and achieve productivity gains at a cost of a slight bump at the start.  I tend to disagree with this, because how often is one modifying their build?  This is why learning and retaining Ant and Maven is so difficult (I can't write a &lt;tt&gt;copy&lt;/tt&gt; in Ant without a trip to the docs).  At any rate, this was a good talk and great overview of sbt, and, despite me not being into the crazy symbols, I will take it over Maven or Ant any day.  At least it's based in a real programming language and not some XML nonsense.
&lt;h3&gt;Processing with Spde&lt;/h3&gt;
&lt;h4&gt;by Nathan Hamblen&lt;/h4&gt;
&lt;p&gt;
This was a brief over of Processing, for those unfamiliar with this (horribly&amp;#8208;named) visualization tool and then a review of the Scala bindingns the presenter had created.  Interestingly, he created &lt;a href=&quot;http://technically.us/spde/About&quot;&gt;SPDE&lt;/a&gt; as an SBT plugin so that users could gain the benefit of SBT's automatic re-compilation and running features.  His plugin + a text editor is a makeshift IDE for Processing, which is pretty cool.  It was very high-level and didn't get into too much detail, but the Scala code was, as expected, much more concise than the Java code.
&lt;/p&gt;
&lt;h3&gt;Sneaking Scala Into your Organization&lt;/h3&gt;
&lt;h4&gt;by Me!&lt;/h4&gt;
&lt;p&gt;
I was pretty nervous, as the many of the previous speakers' topics were all quite heady, but I had practiced my ass off, and delivered the talk as well as I could.  I think it was pretty well received and got some good questions.  I had talked with a few people previously in the conference who were using testing as a way to get Scala into their jobs and a few other people who were interested in what I had to say.  Several people were curious as to how the other developers at OPOWER liked Scala.  I felt pretty good about it.
&lt;/p&gt;
&lt;h3&gt;Future of Scala&lt;/h3&gt;
&lt;h4&gt;by The Scala Team&lt;/h4&gt;
&lt;p&gt;
For this, we broke into small groups and basically unloaded on a poor member of the Scala team as to how anything related to Scala could be better.  Then, the Scala team assembled all of this info while Martin gave a very long term roadmap for Scala.  I do worry that the universe will never catch up to Martin and Scala team as they add more and more advanced and innovative features.
&lt;/p&gt;
&lt;p&gt;
After this, a member of the Scala team did a very fast tour of the feedback.  I wish the entire list could be posted; there was a lot of very heartening complaints in there that would not be obvious from the Scala mailing list (e.g.  hate on the underscore, desire to be less academic in terminology)  This fed my (arguably self-biased) impressions that people want to get Scala into industry and that there is a large hole in this part of the Scala universe.
&lt;/p&gt;
&lt;p&gt;
There were also some updates on IntelliJ's support for Scala.  They sound way ahead of the curve compared to Eclipse and NetBeans, but I was a bit frightened by IDEA's  guy saying that they way people learn languages is to ask for auto-completion and see what's available.  I see this trend all to often and I think it's harmful.  More on that later.
&lt;/p&gt;
&lt;h3&gt;Overall&lt;/h3&gt;
&lt;p&gt;
Despite still being stuck in Geneva, I'm glad I went.  Giving my talk was fun, but it was also great to hear about all the many ways in which people are using Scala.  I went in expecting massive academia overload, with a lot of theoretical type system and functional programming talk and got, instead, a wide variety of topics and just the right amount of academia (i.e. not that much).  Really encouraging.  Also encouraging is that ScalaDays 2011 will likely be in the Bay Area, which is a much nicer place to get stuck that stupid Geneva.
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The only four types of classes in your OO system</title>
   <link href="http://www.naildrivin5.com/blog/2010/03/08/object-oriented-design.html"/>
   <updated>2010-03-08T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/03/08/object-oriented-design</id>
   <content type="html">&lt;p&gt;
Object-Oriented design is hard, especially in a large application.  It's not always clear where logic should go, and there's often no &quot;right place&quot; to  put a piece of code.  I've found that there are four distinct types of classes that, if you stick to them, can make your code a lot more understandable, and can provide clear direction as to the age-old question of &quot;where does this code go?&quot;
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;0. Background&lt;/h2&gt;
The J2EE way is to have model objects be stupid structs, and have all business logic in a service layer (this is actually very close to a classic &quot;functional programming&quot; way of doing things; ironic that many Java devs eschew FP).  Spring lets you do whatever you want, but more or less follows this pattern.  
While the &quot;Rails Way&quot; is to put business logic on the model objects, I think the &quot;service layer&quot; concept &lt;a href=&quot;http://www.engineyard.com/blog/2010/let-them-code-cake/&quot;&gt;is eventually going to be common practice&lt;/a&gt;.
So, I've found that I very rarely make a pure &quot;by-the-book according-to-Hoyle&quot; OO-compliant class; I've settled on four patterns that seem to cover pretty much everything.  I've also noticed that when these patterns get mixed together, you get trouble.
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;1. The Record&lt;/h2&gt;
The &lt;i&gt;record&lt;/i&gt; is a dumb struct that you usually need to appease your object-relational mapper.  You may need them elsewhere to just name and type some set of data that you either can't model as a tuple because of your language, or don't want to model as a tuple because of some complexity.  A record typically has methods that merely expose it's contents and often need to be mutable for the reasons stated.  You might have derived fields that are convieniences and not based on your core business logic.  An easy example is a person.  They have a name and a birthdate, and you might derive their age from that:
&lt;script src=&quot;http://gist.github.com/319943.js?file=AStruct.java&quot;&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;2. The Immutable Object&lt;/h2&gt;
This is the closest to a pure &quot;object-oriented&quot; design.  Classes of this type are immutable and should hold data you will use a lot in your system.  They may also probably have some business-logic attached as methods; this business logic should be entirely focused on the object and its contents.  Typical methods will give you more complex information about the data the object contains, or will vend new objects of the same type, based on the method and parameters called.  
&lt;/p&gt;
&lt;p&gt;
This is the most clear distinction (in my mind) between functional programming and object-oriented programming.  In an FP world, the data being operated on would be loosely defined (if at all) and you'd have functions that transform it.  In an OO world, your object's data is clearly defined (by the class fields/accessors), and the operations available are the methods of the class.  When you require that the objects of the class be immutable, you have a very nice encapsulated package of data and operations.  This, to me, seems a lot easier to deal with than a &quot;module&quot; of functions and some tuples (or lists of tuples) that the functions operate on.  Scala makes it very easy to create classes like this.  It's probably one of the few languages that does so (Java certainly is no help, but it &lt;b&gt;can&lt;/b&gt; be done).
&lt;script src=&quot;http://gist.github.com/319943.js?file=BObject.java&quot;&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;
The benefits here are huge; immutability allows your codebase to be much more comprehensible, and allows you to use these objects in concurrent situations without worry.  Since they are immutable, their methods are immediate targets for caching if you discover you need to do this to improve performance.
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;3. The Builder&lt;/h2&gt;
While you can certainly use methods (or create methods) on Immutable Object classes to &quot;build up&quot; the object you want, this is often cumbersome, and results in a lot of object creation for no real reason.  The &quot;builder&quot; can be used to make this a bit simpler.  The Builder is a throwaway class whose sole purpose is to create Immutable Objects.  This obviously creates a very tight coupling between the two classes, but this can be worth it.  This is very preferable to a mutable class and, depending on your operating environment, is preferable to making many intermediate objects you will need to create the Immutable Object.
&lt;script src=&quot;http://gist.github.com/319943.js?file=CBuilder.java&quot;&gt;&lt;/script&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;4. The Service&lt;/h2&gt;
The analog of The Record, the &lt;i&gt;service&lt;/i&gt; has no data and all logic.  EJBs are services; they have no internal state, operating on their arguments and returning a result.  Methods of services can be very functional in nature (operating solely on structs or immutable objects), or they may provide functionality that implements complex business logic not logically part of an immutable object's class.  In a vanilla n-tier application, you use services to get data in and out of your database (you might call these DAOs and you might distinguish different types of services for partitioning, but these are all the same sort of class).
&lt;/p&gt;
&lt;p&gt;
Like records, Services are not OO at all; these are the functions to your C programs structs.  But, there is a good reason for this design; you separate concerns, don't need to worry about concurrency (services have no state), and can even horizontally partition &lt;i&gt;where&lt;/i&gt; serivces actually run.
&lt;script src=&quot;http://gist.github.com/319943.js?file=DService.java&quot;&gt;&lt;/script&gt;
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Reading a File in Scala vs. Java vs Ruby</title>
   <link href="http://www.naildrivin5.com/blog/2010/01/26/reading-a-file-in-scala-ruby-java.html"/>
   <updated>2010-01-26T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/01/26/reading-a-file-in-scala-ruby-java</id>
   <content type="html">&lt;p&gt;
Examining the code needed to read a file line by line is a a common way to examine the hoops a programming language makes you jump through.  While Perl certainly
has some one-liners for this, let's start with Ruby, which presents an elegant and clear way of doing it:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;some_file.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readlines&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upcase&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
It really doesn't get any clearer than that.
&lt;/p&gt;
&lt;p&gt;
Here's the canonical Java way of doing it, complete with plenty of places to introduce bugs:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.io.*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ReadFile&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IOException&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;some_file.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;BufferedReader&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BufferedReader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;FileReader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;readLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toUpperCase&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;readLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
Yech.  The need to call &lt;code&gt;readLine()&lt;/code&gt; twice kinda sucks.  We could use a do-while, but that requires a second &lt;code&gt;line != null&lt;/code&gt; check.  Personally, I like to forget the second &lt;code&gt;readLine()&lt;/code&gt; and wonder why my code runs forever :)  That being said, this was extremely easy to figure out, even the very first time I did it in 1998.  The class names are obvious, and the documentation is excellent.
&lt;/p&gt;
&lt;p&gt;
Scala to the rescue, right?
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;scala.io._&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ReadFile&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Application&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;some_file.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getLines&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;trim&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toUpperCase&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
This was a slight pain figure out.  I looked in &lt;code&gt;scala.io&lt;/code&gt; and, of the few classes that were there (including a curiously named &lt;code&gt;BytePickle&lt;/code&gt;), it appeared as though &lt;code&gt;Source&lt;/code&gt; was the class to use.  Of course, there's no easy way to create one from the constructor, and the scaladoc doesn't just say &quot;Dude, look at the &lt;code&gt;Source&lt;/code&gt; object&quot;.  Once I looked through the &lt;code&gt;Source&lt;/code&gt; object's scaladoc, the solution presented itself.
&lt;/p&gt;
&lt;p&gt;
Of course, unlike every other line-traversing library in the known universe, &lt;code&gt;Source&lt;/code&gt; leaves the line endings on.  This is thankfully fixed in 2.8 (by which I mean 2.8 breaks 2.7's implementation, which is a strange thing for a point release to do).  The real question is: &quot;Is this how I'm supposed to read files in Scala?&quot;.  With a class called &lt;nobr&gt;&lt;code&gt;Source?!&lt;/code&gt;&lt;/nobr&gt;.  The scaladoc says that this class represents &quot;an iterable representation of source files&quot;.  That might explain the strange methods like &lt;code&gt;reportError&lt;/code&gt; and &lt;code&gt;reportWarning&lt;/code&gt;.  I guess this is only for writing the Scala compiler?   If so, &lt;code&gt;scala.io&lt;/code&gt; seems an odd place to put this.
&lt;/p&gt;
&lt;p&gt;
So, my answer is &quot;No, this &lt;strong&gt;cannot&lt;/strong&gt; be how to canonically read files in Scala&quot;.  Since the Java way kinda, well, sucks, what alternatives are there?  There's &lt;code&gt;&lt;a href=&quot;http://scalax.scalaforge.org/api/&quot;&gt;scalax.io&lt;/a&gt;&lt;/code&gt;, which seems to implement this as a class called, curiously, &lt;code&gt;FileExtras&lt;/code&gt;.    I'm not sure if this code is actively maintained, but it's documented in classic Scala style: terse and full of loaded terms like &quot;nonstrict&quot;. Nevertheless, there seems to be some code here to easily read a file &quot;the easy way&quot; (despite some distracting names).
&lt;/p&gt;
&lt;p&gt;
This points out a big difference between &quot;Scala the language&quot; and &quot;Scala the library&quot;.  Scala the language is very interesting and has a lot of potential.  Scala the library is schizophrenic at best; it's not sure if it wants to be OO, functional, or what.  The documentation ranges from sparse to absent, and the overall designs of the classes and package range for sublime to baffling.  Years different from Java 1.1.
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Unicode in Your Domain Names</title>
   <link href="http://www.naildrivin5.com/blog/2010/01/24/unicode-domain-names.html"/>
   <updated>2010-01-24T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/01/24/unicode-domain-names</id>
   <content type="html">&lt;p&gt;
Got a few questions about how I set up &lt;a href=&quot;http://&amp;#10106;&amp;#10144;.ws/&quot;&gt;&amp;#10106;&amp;#10144;.ws&lt;/a&gt; (which is powered
by &lt;a href=&quot;http://www.github.com/davetron5000/shorty&quot;&gt;Shorty&lt;/a&gt;, my &lt;a href=&quot;2009-11-23-good-bad-ugly-scala-url-shortener.html&quot;&gt;Scala-based URL shortener&lt;/a&gt;), so I thought I'd write up how I got it working.  Short answer is that it was pretty easy.
&lt;/p&gt;
&lt;p&gt;
I got the idea from &lt;a href=&quot;http://www.daringfireball.net&quot;&gt;John Gruber&lt;/a&gt;, who made a similar thing for his site to post entries on &lt;a href=&quot;http://www.twitter.com/daringfireball&quot;&gt;@daringfireball&lt;/a&gt;.  The trickiest part was figuring out what this was called so I could find out who could sell me a domain with unicode characters in it.
&lt;/p&gt;
&lt;p&gt;
It turns out, this is called an IDN (short for &lt;a href=&quot;http://en.wikipedia.org/wiki/Internationalized_domain_name&quot;&gt;Internationalized Domain Name&lt;/a&gt;), and not everyone will sell you one.  Couple that with the need to get a non-&lt;code&gt;.com&lt;/code&gt; domain, and I had to hunt around for a while.
&lt;/p&gt;
&lt;p&gt;
I ended up going with &lt;a href=&quot;http://www.dynadot.com/&quot;&gt;DynaDot&lt;/a&gt; as they could provide the wacky hostname that I wanted as well as a &lt;code&gt;.ws&lt;/code&gt; TLD registration.  I was amazed at the number of domain regstrars whose web forms could not handle Unicode.
It's been almost 7 years since &lt;a href=&quot;http://www.joelonsoftware.com/articles/Unicode.html&quot;&gt;Joel Spolsky&lt;/a&gt; wrote his screed on dealing with Unicode, so I don't know what the deal is.
&lt;/p&gt;
&lt;p&gt;
At any rate, the tricky bit in actually &lt;b&gt;using&lt;/b&gt; the domain, because a) entering &amp;#10106;&amp;#10144; into vim is nontrivial, and b) I doubt that Apache's config file would work with unicode characters in it.  Enter &lt;a href=&quot;http://en.wikipedia.org/wiki/Punycode&quot;&gt;Punycode&lt;/a&gt;, which is an asciification of any IDN.  Fortunately, the domain host provides the Punycode for your IDN, so configuring apache was a matter of:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;VirtualHost&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;XXXXX&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;ServerName&lt;/span&gt; xn--dfi5d.ws
&lt;span class=&quot;nb&quot;&gt;ServerAlias&lt;/span&gt; www.xn--dfi5d.ws
&lt;span class=&quot;nb&quot;&gt;DocumentRoot&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;/home/webadmin/xn--dfi5d.ws/html&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;!--&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;whatever else goes here --&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;JkMount&lt;/span&gt; /s* ajp13
&lt;span class=&quot;nb&quot;&gt;JkMount&lt;/span&gt; /s ajp13
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;Directory&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/home/webadmin/xn--dfi5d.ws/html&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;Options&lt;/span&gt; Includes FollowSymLinks
    &lt;span class=&quot;nb&quot;&gt;AllowOverride&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;All&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/Directory&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
At this point, it pretty much worked, although it was sometimes difficult to get curl to work with the non-punyied name.
&lt;/p&gt;
&lt;p&gt;
One thing that was weird was that I found that a &lt;b&gt;lot&lt;/b&gt; of domains I wanted to try were taken or not available (with no explanation).  Often it seemed like the punycode version was a normal looking URL that was taken; I tried several IDNs that had a unicode character with a wierd &quot;5&quot;, and they punyied to an ascii 5.  Not sure what the deal is there, but I eventually found the one I wanted.
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Top 5 Shocking Omissions from Spring MVC</title>
   <link href="http://www.naildrivin5.com/blog/2010/01/09/Top-5-Omissions-From-Spring-MVC.html"/>
   <updated>2010-01-09T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2010/01/09/Top-5-Omissions-From-Spring-MVC</id>
   <content type="html">&lt;p&gt;
Been working with Spring MVC recently.  My enthusiasm has waned somewhat, as I've discovered that for all of it's tweakability and configurableosity, it omits what I believe to be incredibly obvious things:
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Simple, 80/20 conventions by default&lt;/strong&gt; - While the phrase &quot;convention over configuration&quot; appears numerous times
  in the Spring documentation, it is &lt;strong&gt;still&lt;/strong&gt; unable to call the &lt;code&gt;foo&lt;/code&gt; method of the class
  &lt;code&gt;BarController&lt;/code&gt; when I request the url &lt;code&gt;bar/foo&lt;/code&gt; without a lot of configuration, some of which subtly conflicts
  and causes silent failures.   The default configuration is useless&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Debugging the Routing&lt;/strong&gt; - I shovel angle bracket after annotation after angle bracket into Spring and it simply &lt;strong&gt;can not&lt;/strong&gt; tell me what
  URL patterns are mapped to where, and why a given URL isn't mapped, nor what to do to get it mapped. It's &lt;strong&gt;whole purpose is to map URLs to controllers&lt;/strong&gt;.
  Shocking.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simple internal routing without magic strings&lt;/strong&gt; - If I've mapped &lt;code&gt;FooController&lt;/code&gt;'s &lt;code&gt;bar&lt;/code&gt;
  method, shouldn't I be able to redirect/route to that in code via &lt;code&gt;route(FooController.class,&quot;bar&quot;)&lt;/code&gt;, regardless of the specific URL that
  &lt;code&gt;FooController&lt;/code&gt; and &lt;code&gt;bar&lt;/code&gt; respond to?  Instead, I've got magic strings everywhere and if my urls ever change, god help me.  And don't get me 
  started about accessing this stuff via tests.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simple web-testing&lt;/strong&gt; - Adding a dependency on JWebUnit doesn't cut it.  Jetty and Tomcat cannot hot deploy.  How do people test these things??!?!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test Fixture Support&lt;/strong&gt; - I had to hack this up with DBUnit.  With maven in the mix, it's a huge hit to productivity, but at least I have it.  What project &lt;strong&gt;doesn't&lt;/strong&gt; need this??!?!&lt;/li&gt;
&lt;/ol&gt;
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Prezi on decoding the Scala Map literal</title>
   <link href="http://www.naildrivin5.com/blog/2009/11/24/scalas-map-literal-as-a-prezi.html"/>
   <updated>2009-11-24T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2009/11/24/scalas-map-literal-as-a-prezi</id>
   <content type="html">&lt;p class=&quot;first&quot;&gt;
If you haven't checked out &lt;a href=&quot;http://www.prezi.com&quot;&gt;Prezi&lt;/a&gt; as a means to create presentations, you really should.  They have rethought the entire
user experience, and it's totally awesome.  To give you a flavor of it, I created a presentation of
my blog on &lt;a href=&quot;/blog/2009/11/12/deconstructing-scala-map-literal.html&quot;&gt;Deconstructing Scala's Map Literal&lt;/a&gt;.  I can't create audio in the format
Prezi requires, so there's no voice over, but I think it still works.
&lt;/p&gt;
&lt;p&gt;
&lt;object id=&quot;prezi_pj5_r8volng6&quot; name=&quot;prezi_pj5_r8volng6&quot; classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; width=&quot;550&quot; height=&quot;400&quot;&gt; &lt;param name=&quot;movie&quot; value=&quot;http://prezi.com/bin/preziloader.swf&quot;/&gt;  &lt;param name=&quot;allowfullscreen&quot; value=&quot;true&quot;/&gt;  &lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;/&gt;  &lt;param name=&quot;bgcolor&quot; value=&quot;#ffffff&quot;/&gt;  &lt;param name=&quot;flashvars&quot; value=&quot;prezi_id=pj5_r8volng6&amp;amp;lock_to_path=1&amp;amp;color=ffffff&amp;amp;autoplay=no&quot;/&gt;  &lt;embed id=&quot;preziEmbed_pj5_r8volng6&quot; name=&quot;preziEmbed_pj5_r8volng6&quot; src=&quot;http://prezi.com/bin/preziloader.swf&quot; type=&quot;application/x-shockwave-flash&quot; allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; width=&quot;550&quot; height=&quot;400&quot; bgcolor=&quot;#ffffff&quot; flashvars=&quot;prezi_id=pj5_r8volng6&amp;amp;lock_to_path=1&amp;amp;color=ffffff&amp;amp;autoplay=no&quot;&gt; &lt;/embed&gt; &lt;/object&gt;
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Writing a URL Shortener in Scala - The Good, The Bad, The Ugly</title>
   <link href="http://www.naildrivin5.com/blog/2009/11/23/good-bad-ugly-scala-url-shortener.html"/>
   <updated>2009-11-23T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2009/11/23/good-bad-ugly-scala-url-shortener</id>
   <content type="html">&lt;p class=&quot;first&quot;&gt;
I finally got around to finishing &lt;a href=&quot;http://www.github.com/davetron5000/shorty&quot;&gt;Shorty&lt;/a&gt;, my url-shortener for my vanity short-domain, 
&lt;a href=&quot;http://&amp;#10106;&amp;#10144;.ws/&quot;&gt;&amp;#10106;&amp;#10144;.ws&lt;/a&gt;.  I did the whole thing in Scala as a way to create a fully-functining application
that I would use and that I could finish in my non-work time.  Scala unequivocally made this task enjoyable and quick.  J2EE, on the other hand, 
did not help one bit.
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;The Good&lt;/h2&gt;
&lt;h3&gt;Scala&lt;/h3&gt;
&lt;/p&gt;
&lt;p&gt;
My Scala code is so much shorter and easier to follow than the Java equivalent.  Consider this code that, given
the request path, finds a controller to handle it, and then calls the appropriate method based upon
the HTTP method:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Some&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;determineMethod&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;GET&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PUT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;POST&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DELETE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
It's highly readable, and very concise; the Java version would've required a lot more variables, some noisier control structures, and a lot more braces and parens.
&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;ScalaTest&lt;/h3&gt;
&lt;/p&gt;
&lt;p&gt;
ScalaTest resulted in a lot more readable code than JUnit or TestNG would've.  Because of Scala's syntax, the tests are also free of weird dots and &quot;literate&quot; syntax that
isn't quite that literate.
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;should respond to get for a URL that is known&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OneUrlController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;738ddf&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getClass&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;equal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;asInstanceOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;equal&lt;/span&gt; 
    &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
The delineation between &quot;expected&quot; and &quot;received&quot; could not be more clear.  &lt;tt&gt;assertEquals&lt;/tt&gt; just isn't the same.
The latest version of ScalaTest has some &lt;a href=&quot;http://www.scalatest.org/getting_started_with_flat_spec&quot;&gt;BDD options&lt;/a&gt; that look really great.
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;The Bad&lt;/h2&gt;
&lt;h3&gt;SBT&lt;/h3&gt;
&lt;/p&gt;
&lt;p&gt;
I really wanted to like &lt;a href=&quot;http://code.google.com/p/simple-build-tool/&quot;&gt;SBT&lt;/a&gt;, and, while it's a billion times better than 
&lt;a href=&quot;/blog/2009/05/13/why-maven-drives-me-absolutely-batty.html&quot;&gt;maven&lt;/a&gt;, it's still not as easy to use as I'd like it to be.
&lt;/p&gt;
&lt;p&gt;
I like:
&lt;ul&gt;
    &lt;li&gt;Building code and downloading dependencies are separate&lt;/li&gt;
    &lt;li&gt;The save/run-tests loop is very handy&lt;/li&gt;
    &lt;li&gt;JavaRebel + re-deploying the webapp on file save is very handy&lt;/li&gt;
&lt;/ul&gt;
However:
&lt;ul&gt;
    &lt;li&gt;The test output is horrid; big huge stack traces&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Constant&lt;/b&gt; &lt;tt&gt;OutOfMemory&lt;/tt&gt; errors that &lt;b&gt;it traps&lt;/b&gt; and then &lt;b&gt;doesn't exit&lt;/b&gt;.  I had to &lt;tt&gt;kill -9&lt;/tt&gt; SBT &lt;b&gt;a lot&lt;/b&gt;&lt;/li&gt;
    &lt;li&gt;Still more complicated than shell scripts&lt;/li&gt;
&lt;/ul&gt;
I believe that a build tool should be a DSL for automating software development tasks, which means it should be more concise and easier to use than UNIX shell scripts.  Ant, Maven, and SBT
fail miserably at this.
&lt;/p&gt;
&lt;p&gt;While SBT is light-years ahead by using an actual programming language, I found it very difficult to customize.  Part of this is that the scaladoc tool gives developers &lt;b&gt;no help&lt;/b&gt; in documenting their API, but, when it comes down to it, Scala and Java are not system automation languages.
&lt;/p&gt;
&lt;h3&gt;scaladoc&lt;/h3&gt;
&lt;p&gt;
Scaladoc is nowhere near as powerful as Javadoc.  It makes it very hard to document how to use your code.   Scala should have a &lt;b&gt;more&lt;/b&gt; advanced documentation system than Java, but it actually has a much more primitive one; even RDoc is better.  Hopefully, as Scala's popularity increases, the tools surrounding it will improve.
&lt;/p&gt;
&lt;p&gt;
&lt;h2&gt;The Ugly&lt;/h2&gt;
&lt;h3&gt;J2EE Deployment&lt;/h3&gt;
&lt;/p&gt;
&lt;p&gt;
Deployment is an underappreciated aspect of why Rails is so easy to use; copy/push your code to the production server, tell it you are running in production, and go.  With J2EE, you get NONE of this. 
&lt;/p&gt;
&lt;p&gt;
If you want to alter configuration based upon environment, you are entirely on your own.  J2EE, Ant, Maven, and SBT give you no real help or support; you have to roll it yourself.  I'm just shocked at this omission; J2EE is &lt;b&gt;ten years old&lt;/b&gt; and &lt;b&gt;still&lt;/b&gt; has not provided a solution for something that &lt;b&gt;every&lt;/b&gt; project needs.  Amazing.
&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Servlet Spec&lt;/h3&gt;
&lt;/p&gt;
&lt;p&gt;
Java 5 is at end of life.  The latest released Servlet Spec &lt;b&gt;still doesn't support generics&lt;/b&gt; and is &lt;b&gt;still&lt;/b&gt; completely schizophrenic about it's API (some methods use &lt;tt&gt;Enumeration&lt;/tt&gt;, some use arrays, some use &lt;tt&gt;Iterable&lt;/tt&gt;.  Ugh).  
&lt;/p&gt;
&lt;p&gt;The 3.0 spec looks slightly more sane, but it really doesn't do us any favors.  &lt;tt&gt;web.xml&lt;/tt&gt; is a trainwreck of stupidity, there's zero support for conventions, and the whole thing just feels like a solution designed for a problem that few of us ever have.
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Make your own literals in Scala</title>
   <link href="http://www.naildrivin5.com/blog/2009/11/14/make-your-own-literal-in-scala.html"/>
   <updated>2009-11-14T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2009/11/14/make-your-own-literal-in-scala</id>
   <content type="html">&lt;p class=&quot;first&quot;&gt;
Following up from my post on &lt;a href=&quot;&quot;&gt;Deconstructing the map literal in Scala&lt;/a&gt;, I thought it might be fun to go the other way around, and create a few literals of own.  Since Scala provides the &lt;i&gt;language features&lt;/i&gt; to enable literal-like syntax, and not the actual literals themselves, we can do a lot of stuff to reduce the amount of typing we have to.
&lt;/p&gt;
&lt;p&gt;
In your production code, you probably wouldn't use a lot of literals, regardless of language support.  However, in test cases, they are much more common.  If creating
objects in your tests becomes easier, you will tend to write better tests.
&lt;/p&gt;
&lt;p&gt;
Suppose we are writing a Twitter app (that's all the rage these days, anyway).  We might define a &lt;tt&gt;TwitterUser&lt;/tt&gt; class like so:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TwitterUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.twitter.com/&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recentTweets&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// imagine some code here &lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
We might write a few test cases:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;me&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TwitterUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;davetron5000&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;assertEquals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recentTweets&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fake&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TwitterUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;davetron5001&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;assertEquals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fake&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recentTweets&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
and so forth.  It's going to get a bit tedious writing &lt;tt&gt;new TwitterUser&lt;/tt&gt; over and over again.  We could just make a shorter-named method in our test class, but why not use &lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ScalaBasics#Literals_and_Syntactic_Sugar&quot;&gt;the &lt;tt&gt;apply()&lt;/tt&gt; sugar&lt;/a&gt; along with a &lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ScalaObject&quot;&gt;singleton object&lt;/a&gt; to make our own literal?
&lt;/p&gt;
&lt;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// Along with our TwitterUser class def&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;@@&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &amp;quot;@&amp;quot; is a reserved word :(&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TwitterUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// back to our test code&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;me&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@@(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;davetron5000&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fake&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@@(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;davetron5001&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
It's a small bit of code, and we've saved some typing without sacrificing readability, since we take advantage of the way Twitter refers to users via the &quot;@&quot; symbol.
&lt;/p&gt;
&lt;p&gt;
If our app is all about Twitter, we can go a step further and just rename &lt;tt&gt;TwitterUser&lt;/tt&gt; to &lt;tt&gt;@@&lt;/tt&gt; like so:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// This replaces the TwitterUser class &lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// and @@ singleton object&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;@@&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.twitter.com/&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
This takes advantage of (the unfortunately named) &lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/CaseClasses&quot;&gt;case classes&lt;/a&gt; and now our Twitter user class &lt;b&gt;and&lt;/b&gt; literal-like factory are called &lt;tt&gt;@@&lt;/tt&gt;.  This allows, among other things, some more readable case statements.
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@@(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;davetron5000&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;it&amp;#39;s you, dude&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:@@&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;it&amp;#39;s someone else&amp;quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
Now, you certainly don't want to do this for every object in your domain (you'd get a horrible mess of symbols), but for key objects that you are using everywhere, an appropriately chosen literal syntax can make your code very clean and easy to read and modify.
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Deconstructing the Scala Map Literal</title>
   <link href="http://www.naildrivin5.com/blog/2009/11/12/deconstructing-scala-map-literal.html"/>
   <updated>2009-11-12T00:00:00-05:00</updated>
   <id>http://www.naildrivin5.com/blog/2009/11/12/deconstructing-scala-map-literal</id>
   <content type="html">&lt;p class=&quot;first&quot;&gt;
I find that Scala is one giant &lt;a href=&quot;&quot;&gt;Rube Goldberg Machine&lt;/a&gt; that manages to do something not easily be done otherwise.  By this I mean that Scala has many features that, by themselves, seem very strange, but, in combination, enable some very cool functionality.  This is why I initially started my &lt;a href=&quot;http://www.naildrivin5.com/scalatour&quot;&gt;personal tour of Scala&lt;/a&gt;.  I read stuff like &lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ExplcitlyTypedSelfReferences&quot;&gt;explicitly typed self-references&lt;/a&gt; and was left scratching my head.
&lt;/p&gt;
&lt;p&gt;
I thought it might be fun to deconstruct the &quot;map literal&quot; in Scala and observie how the features interact to create a very handy piece of code that isn't baked into the language.  This assumes and understanding of some &lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ScalaBasics&quot;&gt;Scala basics&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Although Java 7 is getting map literals, Scala already has it (or so it appears):

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;band&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Bass&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&amp;quot;Tony&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Guitar&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&amp;quot;Greg&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Drums&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
This is not actually a literal, but enabled by Scala features to make it look like a literal.  Which means that you can use these facilities to make your own literals.  So, how does this work?
&lt;/p&gt;
&lt;p&gt;
Most surprising to a Java programmer is the &lt;tt&gt;-&amp;gt;&lt;/tt&gt; operator.  This makes use of two Scala features:
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ScalaOperators&quot;&gt;Operator-like method naming&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ImplicitConversions&quot;&gt;Implicit Conversions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
It turns out that the &lt;tt&gt;-&amp;gt;&lt;/tt&gt; operator is on the class &lt;tt&gt;Predef.ArrowAssoc&lt;/tt&gt;.  &lt;tt&gt;Predef&lt;/tt&gt; is automatically imported in every Scala program, so you don't need to prefix anything with &lt;tt&gt;Predef&lt;/tt&gt;.  It returns a tuple of its caller and its argument, e.g.
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dave&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrowAssoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dave&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Bass&amp;quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// entry is now (&amp;quot;Dave&amp;quot;,&amp;quot;Bass&amp;quot;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// which is a Tuple2[String,String]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
Of course, we aren't creating &lt;tt&gt;ArrowAssoc&lt;/tt&gt; instances anywhere, so how does this get called?  This is where implicits come in.  Suppose we change our simple example to:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dave&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dave&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Bass&amp;quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// entry is still (&amp;quot;Dave&amp;quot;,&amp;quot;Bass&amp;quot;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// which is a Tuple2[String,String]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
Here, Scala sees that the method &lt;tt&gt;-&amp;gt;&lt;/tt&gt; needs to be called on an &lt;tt&gt;ArrowAssoc&lt;/tt&gt;, but is being called on a &lt;tt&gt;String&lt;/tt&gt;.  Instead of giving up, Scala notices the method: 
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;implicit&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;any2ArrowAssoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; 
  &lt;span class=&quot;kt&quot;&gt;ArrowAssoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrowAssoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
This means that anything at all can be converted into an &lt;tt&gt;ArrowAssoc&lt;/tt&gt; if there's some reason to.  And we have a reason to here.
&lt;/p&gt;
&lt;p&gt;
This means our code is now effectively:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;band&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Bass&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Tony&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Guitar&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Greg&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Drums&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
It's not hard to imagine a &lt;tt&gt;Map&lt;/tt&gt; constructor taking &lt;tt&gt;Tuple2&lt;/tt&gt;, using the first part as the key and the second part as the value, however where is the constructor?  Scala creates objects via the &lt;tt&gt;new&lt;/tt&gt; keyword, just as Java does.  So, what's going on here?
&lt;/p&gt;
&lt;p&gt;
This use two additional Scala features:
&lt;ol&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ScalaBasics#Literals_and_Syntactic_Sugar&quot;&gt;&lt;tt&gt;apply()&lt;/tt&gt;
        shortcutting&lt;/a&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.naildrivin5.com/scalatour/wiki_pages/ScalaObject&quot;&gt;Scala singleton objects&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
This is much simpler to decode than the &lt;tt&gt;-&amp;gt;&lt;/tt&gt; method; there is simply an object in scope named &lt;tt&gt;Map&lt;/tt&gt;, and it has an &lt;tt&gt;apply&lt;/tt&gt; method that takes a variable list of &lt;tt&gt;Tuple2&lt;/tt&gt; objects.  Scala interprets a method-call syntax on an object, but lacking a method name, as a call to the &lt;tt&gt;apply&lt;/tt&gt; method of that object (if it exists).  So, removing this, we have:
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;band&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Bass&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt;
                      &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Tony&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Guitar&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt;
                      &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Greg&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Drums&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
That's all there is to it!  A few things to note about this:
&lt;ul&gt;
    &lt;li&gt;Without the application of some Scala features, it's pretty ugly&lt;/li&gt;
    &lt;li&gt;The language itself didn't need to implement a special &quot;map literal&quot;; it simply combines smaller features
    in a way to make it appear as though it does.  You can even create your own &quot;literals&quot; rather than waiting for
    the language to implement them&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Why Github Can Open-Source Their Libraries</title>
   <link href="http://www.naildrivin5.com/blog/2009/11/01/why-gitub-can-opensource-their-libraries.html"/>
   <updated>2009-11-01T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2009/11/01/why-gitub-can-opensource-their-libraries</id>
   <content type="html">&lt;p class=&quot;first&quot;&gt;
One thing I love about Github is that they open-source a &lt;b&gt;lot&lt;/b&gt; of their internal tools that power the site.  What's interesting is that, unlike SourceForge, they open source little bits and pieces; tiny libraries that do one specific thing.  These things are supremely useful (I use &lt;a href=&quot;http://www.github.com/davetron5000/grit&quot;&gt;Grit&lt;/a&gt; and &lt;a href=&quot;http://www.github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt; quite often).
&lt;/p&gt;
&lt;p&gt;This is a huge benefit to them; their products become higher-quality through contribution, and their talent-pool increases due to their contribution to the community; they are positioned as a technical leader and social force in the development community.  I've often wondered why more companies don't do this and what's really involved?
&lt;/p&gt;
&lt;p&gt;
There are three main hurdles to overcome in order to do this:
&lt;ul&gt;
    &lt;li&gt;&lt;b&gt;Usefulness&lt;/b&gt; - do you have code that someone will find useful?&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Legalish&lt;/b&gt; - are you comfortable giving away some part of your company's intellectual property?&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Technical&lt;/b&gt; - does your technical infrastructure support extraction, collaboration, and re-integration?&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Usefulness&lt;/h3&gt;
I think comparing Github to Sourceforge makes this point very clear.  While SourceForge does &lt;b&gt;more&lt;/b&gt; than, say, &lt;a href=&quot;http://github.com/mojombo/bert&quot;&gt;BERT&lt;/a&gt;, it's just a big huge all-or-nothing proposition; Github has extracted small parts of their infrastructure useful outside the realm of &quot;software project hosting&quot;, resulting in many useful, fine-grained libraries.
&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Legalish&lt;/h3&gt;
The issue here is essentially to determine if the gains achieved by open-sourcing some of your code are &lt;i&gt;greater&lt;/i&gt; than the competitive advantage &lt;i&gt;lost&lt;/i&gt; by doing so.  Again, the ability to extract small, focused, and useful pieces of functionality is key.  Github isn't open-sourcing their entire infrastructure; just the parts that are really useful and not incidental to their success (though one may argue that their IP has &lt;b&gt;nothing&lt;/b&gt; to do with their success).
&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Technical&lt;/h3&gt;
Here's where things get interesting.  Extracting a small, useful piece of technology from your application, without revealing any trade secrets or other IP can be a challenging task.  Add to that the infrastructure needed to manage and incorporate contributions, and your technical infrastructure could be the main barrier to interacting with the community (and &lt;b&gt;not&lt;/b&gt; the lawyers!).
&lt;/p&gt;
&lt;p&gt;
My company struggles with this daily, as our tools were just not designed to make extraction and management of dependencies easy.  Our problem is almost entirely based on tooling and technology choice (which I'll get into in a further post).
&lt;/p&gt;
&lt;p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
The advantages to open-sourcing some of your code are obvious: you can improve the quality of your codebase while improving your standing in the community (which enahnces your ability to attract top-talent).  You just need to make sure your technical infrastructure is built for it, and that the lines of communication between the development staff and the legal staff are clear and functional.
&lt;/p&gt;
&lt;p&gt;
That Github routinely open-sources bits of their code speaks volumes to the choices they've made as an organization, as well as their technical prowess.
&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>An anecdote about Joel Spolksy at DevDays DC</title>
   <link href="http://www.naildrivin5.com/blog/2009/10/27/joel-spolsky-at-devdays.html"/>
   <updated>2009-10-27T00:00:00-04:00</updated>
   <id>http://www.naildrivin5.com/blog/2009/10/27/joel-spolsky-at-devdays</id>
   <content type="html">&lt;p&gt;
I had signed up to volunteer at DC's DevDays, however &lt;a href=&quot;http://www.opower.com&quot;&gt;My Company&lt;/a&gt; decided to be a local sponsor.  Part of that involed us having some time for a 15-minute presentation during the lunch break.  We were told that other sponsors would be doing something similar.  I worked up a &lt;a href=&quot;http://www.slideshare.net/davetron5000/measuring-agile-process-shorter-2359457&quot;&gt;brief presentation on how we improve our development process with each iteration&lt;/a&gt;.  I figured it would be of interest and not be too (obviously) self-promoting.
&lt;/p&gt;
&lt;p&gt;
We get there and find out that not only are none of the other sponsors doing this, but we can't go at lunch, because Joel very-much wanted these things to be &quot;optional&quot; and, The State Theater being near almost nowhere to go have lunch, everyone would be stuck there and &quot;forced&quot; to watch our presentation.  So, we'd be going &lt;b&gt;after&lt;/b&gt; the entire conference was over.  
&lt;/p&gt;
&lt;p&gt;
I have no problem with this at all; it's his/their conference after all.  But, we probably wouldn't have bothered if we had known this ahead of time. Nevertheless, I &lt;a href=&quot;http://search.twitter.com/search?q=process+%23devdays+from%3Adavetron5000&quot;&gt;tweeted&lt;/a&gt; to the #DevDays hashtag (showing up on the big screen between speakers) and looked forward to it anyway.  As a member of a crappy local band, I've played some gigs to no-one, so it's no big deal.
&lt;/p&gt;
&lt;p&gt;
For most of the day the end of the schedule looked like:
&lt;ul&gt;
    &lt;li style=&quot;font-size: 120%&quot;&gt;4:15 - JQuery&lt;/li&gt;
    &lt;li style=&quot;font-size: 120%&quot;&gt;5:30 - Goodbye!&lt;/li&gt;
    &lt;li style=&quot;font-size: 70%&quot;&gt;(unspecified showcase for OPOWER (formerly Positive Energy))&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
Toward the end, Joel came by, introduced himself, and got my info so he could mention it in his closing remarks.  We discussed some logistics and he was very polite, but obviously had a lot going on.  
&lt;/p&gt;
&lt;p&gt;
While Richard Worth was finishing up his JQuery talk, I head to the back.  The stagehand gets me set up and Joel is about to go deliver the &quot;goodbye and thanks&quot; speech.   Here is my mostly accurate transcription of our brief discussion:
&lt;ul&gt;
    &lt;li&gt;&lt;b&gt;Joel:&lt;/b&gt; &lt;i&gt;OK, I'm gonna go out, say goodbye, and then I'll play a song that goes for about 4 minutes.  After that,
        you can head out and start&lt;/i&gt;&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Me:&lt;/b&gt; &lt;i&gt;No problem, can you or someone cue me when the song is almost over? [you couldn't hear much back there and I
        didn't know the song]&lt;/i&gt;&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Joel:&lt;/b&gt; &lt;i&gt;My experience running these things is that people will start leaving pretty soon, so once it looks like
        everyone's left, you can head out there&lt;/i&gt;&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Me:&lt;/b&gt; &lt;i&gt;Um, ok [mostly amused at his comment and a bit nervious]&lt;/i&gt;&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Joel:&lt;/b&gt; &lt;i&gt;[slighly chuckling] We try to have a strict separation of Editorial and Advertorial content at these&lt;/i&gt;&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Me:&lt;/b&gt; &lt;i&gt;[not quite parsing the word &quot;Advertorial&quot; and also thinking about the hour-long demo on FogBugz] &lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
As I said, it was all good, and a few people DID stick around, but I found the whole thing rather amusing in retrospect.  And I think he actually paid attention to about half of my talk!
&lt;/p&gt;
</content>
 </entry>
 
 
</feed>
