<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>CodeQuirks</title>
	<atom:link href="http://codequirks.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codequirks.com</link>
	<description>Tech Challenges for a Modern Rookie</description>
	<lastBuildDate>Fri, 04 Nov 2011 17:16:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='codequirks.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>CodeQuirks</title>
		<link>http://codequirks.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://codequirks.com/osd.xml" title="CodeQuirks" />
	<atom:link rel='hub' href='http://codequirks.com/?pushpress=hub'/>
		<item>
		<title>My Experience with Play! Scala</title>
		<link>http://codequirks.com/2011/07/06/my-experience-with-play-scala/</link>
		<comments>http://codequirks.com/2011/07/06/my-experience-with-play-scala/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 21:37:43 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
		
		<guid isPermaLink="false">http://codequirks.com/?p=302</guid>
		<description><![CDATA[A few months ago I experimented with the Play! framework, which at the time was only available in Java. I had originally intended to do a blog post on Play! but never got around to it. &#160; In summary, it wasn&#8217;t good. The Java version of Play! actually uses an internal compiler which adds magic&#160;&#8230; <a href="http://codequirks.com/2011/07/06/my-experience-with-play-scala/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=302&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few months ago I experimented with the Play! framework, which at the time was only available in Java. I had originally intended to do a blog post on Play! but never got around to it.<br />
&nbsp;<br />
In summary, it wasn&#8217;t good. The Java version of Play! actually uses an internal compiler which adds magic to the mix. What looked like Java was actually a close relative to Java using nearly-Java syntax with a few special properties. While I had other issues as well, that property alone was an instant deal-breaker. Use Java or don&#8217;t, doing it half-way is a no go.<br />
&nbsp;<br />
So when I heard that Play! Scala was gaining popularity, I was intrigued.<br />
&nbsp;<br />
&nbsp;</p>
<h3>What was I Looking For?</h3>
<p>&nbsp;<br />
My exploration of Play! Scala was actually prompted by the Product Owner I am currently working with. He recently took up Ruby on Rails with the intent to be able to do rapid prototyping of concepts for customers. The prototypes help him determine the customer&#8217;s real wants/needs so that he can communicate them more easily to his teams, and get a better end product. So far the concept works quite well.<br />
&nbsp;<br />
So why Rails? Well, our code-base is primarily Java, so non-Java code inhibits the temptation to keep a prototype. Rails also allows very fast prototyping. You can be doing basic CRUD moments after the rubber hits the road, allowing prototypes to even have limited functionality to more fully test user&#8217;s expectations.<br />
&nbsp;<br />
However, as I am a strong proponent of Scala&#8217;s extensibility and power, I was curious; why Rails?<br />
&nbsp;<br />
Is it possible for Scala to provide the same ability to build prototypes extremely quickly?<br />
&nbsp;<br />
&nbsp;</p>
<h3>What I Found</h3>
<p>&nbsp;<br />
Play! Scala has some real strengths:</p>
<ul>
<li>Development lifecycle very similar to a dynamic language &#8211; edit, and refresh</li>
<li>Type-safe code without having to declare types often (type inference)</li>
<li>Type-safe templates based on the Scala language</li>
<li>Very fast to go from nothing to running</li>
</ul>
<p>&nbsp;<br />
Unfortunately, it&#8217;s not ready:</p>
<ul>
<li>&#8220;Automated Testing&#8221; is done by clicking a button in the browser. I want CI.</li>
<li>Had a hard time getting CRUD running for Scala</li>
<li>Documentation could use some work <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </li>
</ul>
<p>&nbsp;<br />
Interestingly, CRUD likely would have worked, however I had already tore out the ScalaQuery JDBC implementation in favor of my preferred Squeryl.<br />
&nbsp;<br />
A more thorough tutorial/example would have likely got my CRUD working before I attempted something like Squeryl.<br />
&nbsp;<br />
In fact, a good start-to-finish tutorial application (like a basic Blog), complete with CRUD and authentication, could probably mature the basic &#8220;rails&#8221; (pun totally intended) of Play! Scala to the point that it could directly compete with Ruby on Rails for rapid prototypes.<br />
&nbsp;<br />
Of course, for scalability Scala has many other options that are almost as fast; I&#8217;ll take Lift any day, but I&#8217;ve also heard amazing things about Scalatra, Spray, and a few other frameworks.<br />
&nbsp;<br />
&nbsp;</p>
<h3>Final Thoughts</h3>
<p>More/Better Tutorials.<br />
&nbsp;<br />
Maybe integrate into SBT instead of having a separate executable if Play! Scala is &#8220;true&#8221; Scala.<br />
&nbsp;<br />
Deliverable WARs instead of Play Apps to take advantage of a more well-known deployment lifecycle.<br />
&nbsp;<br />
Easier hooks into testing, with the intent to enable automation for CI.<br />
&nbsp;<br />
Lots of potential here. Given a little more maturity, Play! Scala may become a real option in my mind. For now, it&#8217;s a very interesting project that just has a little further to go.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=302&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/07/06/my-experience-with-play-scala/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>
	</item>
		<item>
		<title>Resisting Progress</title>
		<link>http://codequirks.com/2011/06/20/resisting-progress/</link>
		<comments>http://codequirks.com/2011/06/20/resisting-progress/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 15:34:46 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[sbt]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=294</guid>
		<description><![CDATA[Summarized in an Image &#160; &#160; Why fly when a car will do? Don&#8217;t get me wrong, I drive regularly. Occasionally I even take long trips by the pavement when the tarmac is too pricey. However, there&#8217;s a limit. Flying is faster, safer, and more convenient. When cost (both price and time-overhead) allows, I&#8217;d prefer&#160;&#8230; <a href="http://codequirks.com/2011/06/20/resisting-progress/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=294&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Summarized in an Image</h2>
<p><img class="aligncenter" style="width:400px;height:637px;" src="http://kodequirks.files.wordpress.com/2011/06/evolution.png?w=497" alt="" /><br />
&nbsp;<br />
&nbsp;</p>
<h2>Why fly when a car will do?</h2>
<p>Don&#8217;t get me wrong, I drive regularly. Occasionally I even take long trips by the pavement when the tarmac is too pricey. However, there&#8217;s a limit. Flying is faster, safer, and more convenient. When cost (both price and time-overhead) allows, I&#8217;d prefer to be in the air.<br />
&nbsp;<br />
In a way, that&#8217;s where the comparison breaks down. While Maven is generally faster, safer, and far more convenient than Ant, nobody is charging you exorbitant prices to use it. Both are free, it&#8217;s up to you to pick which.<br />
&nbsp;<br />
Unlike real air travel, Maven also avoids long up-front overhead costs. To fly for real I have to head to the airport early, get through security, sit on my hands for an hour, then jump on the plane and wait another twenty minutes before takeoff. Maven doesn&#8217;t have that. I&#8217;m running in about a half-dozen lines, and a couple directories.<br />
&nbsp;<br />
Amusingly enough, I&#8217;m still talking about Maven and Ant here. I&#8217;ve personally moved on to SBT and I&#8217;m loving it. One quick command-line call, and I&#8217;ve got my project rolling. I can customize where I want to whatever extent I want because I get to use real code to do so. For me, it&#8217;s like moving from the incredible velocity of a jet plane, and strapping myself inside a rocket bound for wherever I want to go.<br />
&nbsp;<br />
Still, I&#8217;m baffled every now and then when I look back down on earth to see someone driving their car because &#8220;it&#8217;s the way it&#8217;s always been done&#8221;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/294/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=294&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/06/20/resisting-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2011/06/evolution.png" medium="image" />
	</item>
		<item>
		<title>And then I realized&#8230; Java is Frustrating!</title>
		<link>http://codequirks.com/2011/05/27/and-then-i-realized-java-is-frustrating/</link>
		<comments>http://codequirks.com/2011/05/27/and-then-i-realized-java-is-frustrating/#comments</comments>
		<pubDate>Fri, 27 May 2011 19:43:02 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=284</guid>
		<description><![CDATA[Lately I&#8217;ve been slowly learning the Scala language in my spare time. It&#8217;s an interesting experience, and it&#8217;s incredibly exciting to learn while hearing buzz such as the rumour that Quora is moving to Scala. With other major players using the language, such as Twitter, LinkedIn, and Foursquare (just to repeat @yaaang&#8217;s non-exhaustive list), its&#160;&#8230; <a href="http://codequirks.com/2011/05/27/and-then-i-realized-java-is-frustrating/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=284&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/Ib2J0" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Lately I&#8217;ve been slowly learning the Scala language in my spare time. It&#8217;s an interesting experience, and it&#8217;s incredibly exciting to learn while hearing buzz such as <a href="https://twitter.com/#!/yaaang/status/73902613296455680">the rumour that Quora is moving to Scala</a>. With other major players using the language, such as Twitter, LinkedIn, and Foursquare (just to repeat @yaaang&#8217;s non-exhaustive list), its keeps learning relevant and exciting.</p>
<p>Unfortunately, it has a few drawbacks.</p>
<p>I was introduced to Scala through <a href="http://php.jglobal.com/blog/">Mike Nash</a>, a coworker of mine who dove into the language first. While learning, I would regularly poke fun at his occasional Scala-isms while he tried to write Java code. For example:</p>
<pre class="brush: java;">
public class ServiceTest {
    @Test
    public void testSummation() {
        List&lt;Integer&gt; intsToSum = List(1, 2, 3);  // Uh... that's not Java mike...
        int sum = service.sum(intsToSum);
        assertEquals(6, sum);

        // At least he didn't intsToSum.reduceLeft(_+_) ;P
    }
}
</pre>
<p>Even as I slowly slipped into the same habit, I would still tease, but today I realized that the real frustration isn&#8217;t the occasional Scala-ism. The biggest pain-point I&#8217;ve found so far in learning Scala is having Scala in my personal toolkit, but not having it in our team&#8217;s toolkit.</p>
<p>Scala is a JVM language. It would compile into the WAR-file and be indistinguishable to our customer. It&#8217;s statically typed (which I like), but still uses type-inference to avoid the verbosity of most static-type languages. It&#8217;s extremely expressive, complete with the power of the functional and the object oriented paradigms. It&#8217;s all those things, and more, and I can&#8217;t use it.</p>
<pre class="brush: scala;">
case class ProductFamilyCategoryWithChildren(category : ProductFamilyCategory, families : List[ProductFamily]);
</pre>
<pre class="brush: java;">
public class ProductFamilyCategoryWithChildren {
    private ProductFamilyCategory category;
    private List&lt;ProductFamily&gt; families;

    public ProductFamilyCategoryWithChildren(ProductFamilyCategory category, List&lt;ProductFamily&gt; families) {
        this.category = category;
        this.families = families;
    }

    public ProductFamilyCategory getCategory() { return category; }
    public List&lt;ProductFamily&gt; getFamilies() { return families; }
}
</pre>
<p>That&#8217;s 1 line of Scala to 12 of Java. There are 111 characters of Scala to 456 of Java. I stare at both, swallow my pride a little, delete the Scala version, and move on&#8230;</p>
<hr />
<a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/Ib2J0" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F27%and-then-i-realized-java-is-frustrating%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=284&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/05/27/and-then-i-realized-java-is-frustrating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>ScaLearning 7 &#8211; Distributing Concurrent Tests</title>
		<link>http://codequirks.com/2011/05/20/scalearning-7-distributing-concurrent-tests/</link>
		<comments>http://codequirks.com/2011/05/20/scalearning-7-distributing-concurrent-tests/#comments</comments>
		<pubDate>Fri, 20 May 2011 20:43:54 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[actors]]></category>
		<category><![CDATA[akka]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[ScaLearning]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=279</guid>
		<description><![CDATA[Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala. “ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or&#160;&#8230; <a href="http://codequirks.com/2011/05/20/scalearning-7-distributing-concurrent-tests/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=279&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/Q678U" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/scalearning_7_distributing_concurrent_tests.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala.</p>
<p>“ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or otherwise worthy of talking about.<br />
&nbsp;<br />
&nbsp;</p>
<h3>Motivation</h3>
<p>Recently in order to gain confidence in our web application, our team decided it pragmatic to run a series of tests over a deployed version of the application complete with production-like database. A simple suite of non-destructive tests we could run in any environment was quickly put together.<br />
&nbsp;<br />
Unfortunately one of our simplest tests quickly began causing us trouble. The test emulated a search spider, crawling every link it found on the entire site in an exhaustive graph traversal complete with cycle-detection. Unfortunately, the test ran for over 24 hours without completing.<br />
&nbsp;<br />
While we&#8217;ve made other optimizations to improve performance of the test (such as excluding sufficiently similar pages), the topic of today&#8217;s post is the concurrency we introduced in order to help take the edge off test time.<br />
&nbsp;<br />
&nbsp;</p>
<h3>Distributing Concurrent Tests</h3>
<p>Our goal was relatively simple. We wished to run a very simple test across many thousands of URLs:</p>
<pre class="brush: scala;">
def testSingleUrl(nextUrl : String) = {
      client.open(nextUrl)
      client.statusCode should equal(200)
}
</pre>
<p>&nbsp;<br />
&nbsp;<br />
If either of the calls inside this test fail, an exception would be thrown. This was an acceptable way of detecting test failure. However, the test needed to do a bit more &#8211; traverse the graph:</p>
<pre class="brush: scala;">
  def testUrl(nextUrl: String): Unit = {
      if (wasVisited(nextUrl)) return

      val client = new HtmlUnitRunner
      client.open(nextUrl)
      client.statusCode should equal(200)

      registerVisitedUrl(nextUrl)

      JListWrapper(client.currentPage.getAnchors())
              .map(_.getAttribute(&quot;href&quot;))
              .filter(isLinkValid(_))
              .foreach((a: String) =&gt; {
                      markForTesting(nextUrl)
              })
  }
</pre>
<p>Of course, this was called by a method which pushed and popped from a stack, and &#8220;markForTesting&#8221; pushed a new link onto that stack. This code worked great sequentially, but we wanted it to operate concurrently in order to minimize testing time. For this, we employed Akka&#8217;s actors:</p>
<pre class="brush: scala;">
class ConcurrentTest extends Actor {
  def receive = {
    case name: (() =&gt; Unit) =&gt;
      try {
        name()
        self reply(true)
      } catch {
        case t: Throwable =&gt;
          t.printStackTrace()
          self reply(false)
      }
    case _ =&gt;
      println(&quot;Actor received an unrecognized message&quot;)
      self reply(false)
  }
}
</pre>
<p>ConcurrentTest, as you can see, is the driver behind an individual run of the test method:</p>
<pre class="brush: scala;">
val testRunner = actorOf[ConcurrentTest].start()
val result = testRunner !!! (() =&gt; testUrl(&quot;/index.html&quot;)
// Other code can go here
result.get
</pre>
<p>&nbsp;<br />
&nbsp;<br />
Assuming the methods called within testUrl are thread-safe (which we also did using Actors), this will run a single test using a second Thread, and allow us to continue on with our business. However, since there&#8217;s only a single Actor here, we only have one Thread with which to process URLs. This means that we&#8217;re still effectively opening each link sequentially. </p>
<p>We need a Thread pool, and Akka is glad to provide one:</p>
<pre class="brush: scala;">
class Master(nofWorkers: Int) extends Actor {
  val workers = List.fill(nofWorkers)(actorOf[ConcurrentTest].start())
  val router = Routing.loadBalancerActor(new CyclicIterator(workers)).start()
  val answers = ListBuffer[Future[Boolean]]()

  def receive = {
    case name: (() =&gt; Unit) =&gt; answers += router !!! name
    case &quot;result&quot; =&gt; {
      Futures.awaitAll(answers.toList)
      self reply(answers.foldLeft(true)(_ &amp;&amp; _.result.get))
      workers.foreach(_.stop())
      router.stop()
      self stop()
    }
  }
}
</pre>
<p>&nbsp;<br />
&nbsp;<br />
So far everything I&#8217;ve presented as code came very naturally. In fact, minor modifications for the purpose of blogging notwithstanding, we used the code I&#8217;ve presented so far to test several links across our site very successfully, in a fashion very similar to the following:</p>
<pre class="brush: scala;">
val masterRunner = actorOf(new Master(concurrentActors)).start()
val productList = fetchAllProductsFromDatabase

productList.map(productToUrl(_))
        .foreach(url =&gt; masterRunner ! (() =&gt; testSingleUrl(url)))

((masterRunner !! &quot;result&quot;).getOrElse(false).asInstanceOf[Boolean]) should equal(true)
</pre>
<p>However, when we attempted to apply the same methodology to our crawl test, things didn&#8217;t work as well as we&#8217;d hoped:</p>
<pre class="brush: scala;">
    val masterRunner = actorOf(new Master(concurrentActors)).start()

    // def testUrl as seen above

    def markForTesting(nextUrl : String) {
            masterRunner ! (() =&gt; testUrl(nextUrl))
    }

   def fullTest() = {
            val baseUrl = &quot;/index.html&quot;
            masterRunner ! testUrl(&quot;baseUrl&quot;)

             ((masterRunner !! &quot;result&quot;).getOrElse(false).asInstanceOf[Boolean]) should equal(true)
    }
</pre>
<p>&nbsp;<br />
&nbsp;<br />
The theory was that &#8220;result&#8221; would wait for all of the answers to come back before returning. Unfortunately, that&#8217;s not quite the sequence of events the Actor sees. In reality, after digging, we figured out what messages the actor received:</p>
<ol>
<li>(() =&gt; testUrl(&#8220;/index.html&#8221;)) occurs, which is quickly sent to a ConcurrentTest runner</li>
<li>&#8220;result&#8221; comes next, as it takes a second or two for the runner to open the test</li>
<li>(() =&gt; testUrl(_)) is received for several other URLs as links are scraped off the first page</li>
</ol>
<p>&#8220;result&#8221; doesn&#8217;t actually wait for all the answers to come back, as it has no way of knowing how many answers are actually required. For that matter, we aren&#8217;t sure of that number either, as the test is meant to be dynamic. Instead, &#8220;result&#8221; simply compiles the answers it has so far, and then shuts down all of the actors. This means we get a &#8220;yes&#8221; or &#8220;no&#8221; about &#8220;/index.html&#8221;, but all of the other URLs are still sitting in the mailbox of Master when it&#8217;s shut down. Uh-oh!</p>
<p>So how do we know when we&#8217;re done? Mailbox sizes. We added a new match case to Master which would calculate if it believed the tests to be done yet:</p>
<pre class="brush: scala;">
class Master(nofWorkers: Int) extends Actor {
  ...
  def receive = {
    ...
    case &quot;done&quot; =&gt; { // Added this case, the rest of &quot;Master&quot; remained unchanged
        Futures.awaitAll(answers.toList)
        val overallSize = workers.map(worker =&gt; worker.mailboxSize).foldLeft(0)(_ + _) + router.mailboxSize
        self.reply(overallSize == 0 &amp;&amp; self.mailboxSize == 0)
    }
  }
}
</pre>
<p>&nbsp;<br />
&nbsp;<br />
This code is different than &#8220;result&#8221; in that it actually attempts to detect if the tests are done by:</p>
<ol>
<li>Waiting for all currently outstanding test-methods to complete</li>
<li>Counting any pending messages in the router and worker mailboxes.<br /><i>(This should always be zero, as we&#8217;ve waited for all answers to return, but it&#8217;s still safer to be sure)</i></li>
<li>Counting any pending messages on the master</li>
<li>Return &#8220;true&#8221; if the total pending messages is 0, otherwise &#8220;false&#8221; as more tests have to run</li>
</ol>
<p>This algorithm will work for us because when we run Futures.awaitAll it runs every outstanding test to completion. Any URLs found on the pages to be tested are checked against previously-visited URLs, and added to Master&#8217;s queue if they are new. Since Master is still processing &#8220;done&#8221; those tests will stay on the queue and &#8220;mailboxSize&#8221; will return a positive non-zero number. If, however, no new links are encountered, then there will be no tests waiting on the Master queue, and our &#8220;done&#8221; operation will detect 0 pending tests.</p>
<p>In use:</p>
<pre class="brush: scala;">
val masterRunner = actorOf(new Master(concurrentActors)).start()
def markForTesting(nextUrl : String) = masterRunner ! (() =&gt; testUrl(nextUrl))
// def testUrl as seen above

def fullTest() = {
    val baseUrl = &quot;/index.html&quot;
    masterRunner ! testUrl(&quot;baseUrl&quot;)
    while((masterRunner !! &quot;done&quot;).getOrElse(false).asInstanceOf[Boolean] == false) {
        Thread.sleep(1000);
    }
    ((masterRunner !! &quot;result&quot;).getOrElse(false).asInstanceOf[Boolean]) should equal(true)
}
</pre>
<p>Now we sleep our thread, asking the master if it&#8217;s completed its job once every cycle, until the master claims all of its workers have completed their work and no new work is pending for the master to distribute.</p>
<p>Feedback as to other potential approaches is very welcome, I find the entire topic of concurrency and job distribution very interesting.</p>
<hr />
<a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/Q678U" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/scalearning_7_distributing_concurrent_tests.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F20%2Fscalearning-7-distributing-concurrent-tests%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/279/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=279&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/05/20/scalearning-7-distributing-concurrent-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>ScaLearning 6 &#8211; DSL Exploration &amp; Operator Interpretation</title>
		<link>http://codequirks.com/2011/05/13/scalearning-6-dsl-exploration-operator-interpretation/</link>
		<comments>http://codequirks.com/2011/05/13/scalearning-6-dsl-exploration-operator-interpretation/#comments</comments>
		<pubDate>Fri, 13 May 2011 21:05:18 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[dsl exploration]]></category>
		<category><![CDATA[lolcode]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[ScaLearning]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=268</guid>
		<description><![CDATA[Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala. “ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or&#160;&#8230; <a href="http://codequirks.com/2011/05/13/scalearning-6-dsl-exploration-operator-interpretation/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=268&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/d03bM" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/scalearning_6_dsl_exploration_and_operator_interp.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala.</p>
<p>“ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or otherwise worthy of talking about.<br />
&nbsp;<br />
&nbsp;</p>
<h3>DSL Exploration: Our Tale So Far</h3>
<p>For those interested in the whole DSL Exploration &#8220;mini-series&#8221;, we began with <a href="http://codequirks.com/2011/05/09/scalearning-4-dsl-exploration-and-operator-notation/">DSL Exploration &amp; Operator Notation</a>.</p>
<p>To quickly summarize our tale so far, I decided to explore the creation of a DSL to expose some of Scala&#8217;s nuances. My project of choice was codifying the <a href="http://lolcode.com/">LOLCode</a> language as a Scala DSL. So far we have created a syntax for outputting data to the screen.</p>
<p>Working syntax so far:</p>
<pre class="brush: scala;">
U SEEZ &quot;Hello World&quot; !
U SEEZ &quot;Hello World&quot; !!
</pre>
<p>&nbsp;<br />
&nbsp;</p>
<h3>Learned Lesson 3: Operation Interpretation</h3>
<p>So far we&#8217;ve been doing all of our work in the Scala REPL. While extremely powerful, the REPL does have a few known limitations &#8211; it sometimes interprets a line differently than it would have been interpreted from a source file. Today we&#8217;ll discover one such situation, and explore the reason.</p>
<p>Let us start with a Scala source-file which will act as our basis:</p>
<pre class="brush: scala;">
class Printable(output:String) {
  var bang = false;
  def ! = { print(output); }
  def !! = { println(output); }
}
class OutputStream {
  def SEEZ(output: Printable) : Unit = println(output.toString)
}
val U = new OutputStream

U SEEZ &quot;Hello&quot;!
U SEEZ &quot; World&quot;!!
U SEEZ &quot;Goodbye&quot;!
U SEEZ &quot; World&quot;!!
</pre>
<p>The code above is equivalent to what we were writing into the REPL in previous posts, but let&#8217;s store that in a file <i>ScaLol.scala</i> and run it:</p>
<pre class="brush: bash;">
tcalder:bin tcalder $ scala ScaLol.scala
/.../ScaLol.scala:10: error: value ! is not a member of java.lang.String
U SEEZ &quot;Hello&quot;!
</pre>
<p>Clearly not what the REPL was telling us. At first glance, it now appears as if it&#8217;s completely changed its operational precedence, and that&#8217;s true&#8230; but only sort of.</p>
<p>After trying various combinations of the code (none of which helped), I eventually gave up and started reading the <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf">Scala Reference</a> again.</p>
<p>Let&#8217;s review what we&#8217;ve said so far:</p>
<ul>
<li>Methods with one argument can be used as an infix operator</li>
<li>Methods with no arguments can be used as a postfix operator</li>
<li>Unary operators for !, +, -, and ~ can be used if equivalent &#8220;unary_*&#8221; methods are defined</li>
<li>Postfix operators <u>always</u> have lower precedence than infix operators</li>
<li>Infix operators have an order of precedence which includes letters being lower than special characters</li>
</ul>
<p>Reasoning briefly about our code, the REPL clearly evaluates the &#8220;!&#8221; as a postfix operator, which gives it the lowest precedence and results in:</p>
<pre class="brush: scala;">
U.SEEZ(&quot;Hello&quot;).!()
</pre>
<p>Yet in ScaLol.scala we appear to have attempted to run &#8220;!&#8221; on String. Since Postfix have low precedence, we just be attempting to evaluate &#8220;!&#8221; as an Infix operator. This would make sense since special characters have a higher operational precedence:</p>
<pre class="brush: scala;">
U.SEEZ( &quot;Hello World&quot;.!(.....?) )
</pre>
<p>Now if you&#8217;re like me, you&#8217;re wondering what on earth it could possibly be trying to fill in as the argument to this strange new Infix &#8220;!&#8221;. The answer is, it&#8217;s trying to use the next line as a continuation on the current:</p>
<pre class="brush: scala;">
U.SEEZ(&quot;Hello&quot;.!(U)).SEEZ(&quot;World&quot;... // Or some rough equivalent
</pre>
<p>From the ScalaReference:</p>
<blockquote><p>
Scala is a line-oriented language where statements may be terminated by semicolons or newlines. A newline in a Scala source text is treated as the special token<br />
“nl” if the three following criteria are satisﬁed:</p>
<ol>
<li>The token immediately preceding the newline can terminate a statement.</li>
<li>The token immediately following the newline can begin a statement.</li>
<li>The token appears in a region where newlines are enabled.</li>
</ol>
</blockquote>
<p>&#8220;U&#8221; can start a statement, and &#8220;!&#8221; can terminate one, since the REPL clearly didn&#8217;t get upset at either of these. Newlines are enabled in our code &#8211; there&#8217;s a lot of logic in the Reference that explains why if you&#8217;d like to explore it.</p>
<p>Based on this, we can conclude that our &#8220;\n&#8221; after the &#8220;!&#8221; is, in fact, a &#8220;[nl]&#8220;.</p>
<p>The second piece of the puzzle that we need is the following (summarized) syntactic definitions, expressed in the Scala Ref using <a href="http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form"> Extended Backus–Naur Form</a>:</p>
<blockquote><p>
PostfixExpr ::= InfixExpr [id [nl]]<br />
InfixExpr ::= PrefixExpr<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| InfixExpr id [nl] InfixExpr<br />
PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr</p></blockquote>
<p>In specific, draw your attention to the similarity between the definition of &#8220;PostfixExpr&#8221; and the second definition of &#8220;InfixExpr&#8221;, and pay special attention to our friend &#8220;nl&#8221;.</p>
<p>The following is a (rough) breakdown of what we&#8217;ve actually attempted:</p>
<pre class="brush: plain;">
U SEEZ &quot;Hello World&quot; !
U SEEZ &quot;Goodbye World&quot; !

SimpleExpr id SimpleExpr id nl SimpleExpr id SimpleExpr id

PrefixExpr id PrefixExpr id nl PrefixExpr id PrefixExpr id

InfixExpr id InfixExpr id nl InfixExpr id InfixExpr id
</pre>
<p>Bingo, there&#8217;s our culprit. The second &#8220;id&#8221; in the expression is our &#8220;!&#8221; operator. Based on the formal specification, &#8220;InfixExpr id nl InfixExpr&#8221; can be simplified as a single &#8220;InfixExpr&#8221;, and since &#8220;!&#8221; has higher precedence than &#8220;SEEZ&#8221;, it will clearly be evaluated first.</p>
<p>As a final proof, try saving the following code as &#8220;ScaLol2.scala&#8221; and running it. Note how we use two new-lines in-between &#8220;SEEZ&#8221; calls. This results in two &#8220;nl&#8221; entities instead of one, which prevents the compiler from interpreting an InfixExpr where we didn&#8217;t intend one:</p>
<pre class="brush: scala;">
class Printable(output:String) {
  def ! = { print(output); }
  def !! = { println(output); }
}
class OutputStream {
  def SEEZ(output: String) : Printable = new Printable(output)
}
val U = new OutputStream

U SEEZ &quot;Hello&quot;!

U SEEZ &quot; World&quot;!!

U SEEZ &quot;Goodbye&quot;!

U SEEZ &quot; World&quot;!!
</pre>
<p>The result on my machine:</p>
<pre class="brush: bash;">
tcalder:bin tcalder $ scala ScaLol2.scala
Hello World
Goodbye World
</pre>
<p>That&#8217;s all for this week! I hope today&#8217;s post proved interesting, it was far deeper than I ever expected to go, which was exactly what I was hoping for.</p>
<hr />
<a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/d03bM" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/scalearning_6_dsl_exploration_and_operator_interp.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F13%2Fscalearning-6-dsl-exploration-operator-interpretation%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/268/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/268/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=268&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/05/13/scalearning-6-dsl-exploration-operator-interpretation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>ScaLearning 5 &#8211; DSL Exploration &amp; Operation Precedence</title>
		<link>http://codequirks.com/2011/05/11/scalearning-5-dsl-exploration-operation-precedence/</link>
		<comments>http://codequirks.com/2011/05/11/scalearning-5-dsl-exploration-operation-precedence/#comments</comments>
		<pubDate>Wed, 11 May 2011 19:42:00 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[dsl exploration]]></category>
		<category><![CDATA[lolcode]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[ScaLearning]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=253</guid>
		<description><![CDATA[Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala. “ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or&#160;&#8230; <a href="http://codequirks.com/2011/05/11/scalearning-5-dsl-exploration-operation-precedence/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=253&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/scalearning_5_dsl_exploration_operation_precedence.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala.</p>
<p>“ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or otherwise worthy of talking about.<br />
&nbsp;<br />
&nbsp;</p>
<h3>DSL Exploration: Our Tale So Far</h3>
<p>For those interested in the whole DSL Exploration &#8220;mini-series&#8221;, we began with <a href="http://codequirks.com/2011/05/09/scalearning-4-dsl-exploration-and-operator-notation/">DSL Exploration &amp; Operator Notation</a>.</p>
<p>To quickly summarize our tale so far, I decided to explore the creation of a DSL to expose some of Scala&#8217;s nuances. My project of choice was codifying the <a href="http://lolcode.com/">LOLCode</a> language as a Scala DSL. So far we have created a syntax for outputting data to the screen.</p>
<p>Working syntax so far:</p>
<pre class="brush: scala;">
U SEEZ &quot;Hello World&quot;
</pre>
<p>&nbsp;<br />
&nbsp;</p>
<h3>Learned Lesson 2: Operation Precedence</h3>
<p>Now that we&#8217;ve successfully defined &#8220;U SEEZ&#8221;, the LOLCode spec allows us to add a bang at the end of a sentence to &#8220;cancel&#8221; the newline. While this feels a little backwards, we can attempt it.</p>
<p>Our goal:</p>
<pre class="brush: scala;">
U SEEZ &quot;Hello World&quot; // Includes newline
U SEEZ &quot;Goodbye&quot;! // No newline
</pre>
<p>My first plan of attack was to make &#8220;SEEZ&#8221; return an object that has the &#8220;!&#8221; method, which would do a &#8220;print&#8221; instead of a &#8220;println&#8221;. Fortunately, before attempting this solution I realized that if I were to do so there would be no method call to trigger the non-bang &#8220;println&#8221;.</p>
<p>Attempt two, maybe we can allow SEEZ to accept a different object. That object can have a &#8220;!&#8221; method. Here&#8217;s what I&#8217;m aiming for:</p>
<pre class="brush: scala;">
U.SEEZ( &quot;Hello World&quot;.!() )
</pre>
<p>&nbsp;<br />
We&#8217;ll also need an implicit to turn Strings into this special new object. Here goes.</p>
<pre class="brush: scala;">
scala&gt; class Printable(val text : String, val bang : Boolean) {
     | override def toString() = if (bang) {text} else {text + &quot;\n&quot;}
     | def ! = new Printable(text, !bang)
     | }
defined class Printable

scala&gt; class OutputStream {
     | def SEEZ(p : Printable) = print(p.toString())
     | }
defined class OutputStream

scala&gt; val U = new OutputStream
U: OutputStream = OutputStream@e208506

scala&gt; implicit def stringToPrintable(s : String) : Printable = new Printable(s, false)
stringToPrintable: (s: String)Printable

scala&gt; U SEEZ &quot;Hello World&quot;
Hello World
</pre>
<p>That&#8217;s good news, we&#8217;ve managed to maintain the old behaviour, so let&#8217;s give our new &#8220;!&#8221; method a try:</p>
<pre class="brush: scala;">
scala&gt; U SEEZ &quot;Hello World&quot;!
:10: error: value ! is not a member of Unit
</pre>
<p>Foiled again! So what happened here? As &#8220;println&#8221; returns type &#8220;Unit&#8221;, which is the Scala equivalent to &#8220;void&#8221;, we can venture a guess that the &#8220;!&#8221; method was actually run on the result of &#8220;println&#8221;:</p>
<pre class="brush: scala;">
U.SEEZ(&quot;Hello World&quot;).!()
</pre>
<p>&nbsp;<br />
As I&#8217;m sure you&#8217;ve guessed, the issue at hand is operator precedence. Let&#8217;s experiment a little:</p>
<pre class="brush: scala;">
scala&gt; class MyObj(val v : String) {
     | def in(m : MyObj) = {println(&quot;[&quot; + v + &quot;.in(&quot; + m.v + &quot;)]&quot;); new MyObj(v + m.v) }
     | def post() = {println(&quot;[&quot; + v + &quot;.post()]&quot;); this}
     | def unary_+ = {println(&quot;[&quot; + v + &quot;.pre()]&quot;); this}
     | }
defined class MyObj

scala&gt; implicit def stringToMyObj(s : String) : MyObj = new MyObj(s);
stringToMyObj: (s: String)MyObj

scala&gt; +&quot;a&quot;
[a.pre()]
res2: MyObj = MyObj@7987b796

scala&gt; + &quot;a&quot; in &quot;b&quot;
[a.pre()]
[a.in(b)]
res3: MyObj = MyObj@3cd41115

scala&gt; + &quot;a&quot; in &quot;b&quot; post
[a.pre()]
[a.in(b)]
[ab.post()]
res4: MyObj = MyObj@6dcc55fb

scala&gt; &quot;a&quot; in &quot;b&quot; in &quot;c&quot;
[a.in(b)]
[ab.in(c)]
res5: MyObj = MyObj@69cad977

scala&gt; &quot;a&quot; in &quot;b&quot; post
[a.in(b)]
[ab.post()]
res6: MyObj = MyObj@37b24706

scala&gt; &quot;a&quot; post
[a.post()]
res7: MyObj = MyObj@7ea4b9da

scala&gt; &quot;a&quot;.post in &quot;b&quot;
[a.post()]
[a.in(b)]
res8: MyObj = MyObj@7e28388b

scala&gt; &quot;a&quot; post in &quot;b&quot;
:1: error: ';' expected but string literal found.
       &quot;a&quot; post in &quot;b&quot;
                   ^
</pre>
<p>&nbsp;<br />
&nbsp;<br />
We seem to be allowed to omit all the dots and brackets when we chain infix operators, but we&#8217;re unable to chain an infix operator to the result of a postfix operator unless the postfix used a dot to call. The postfix call at the end of a chain also seems to apply to the result of the previous infix call.</p>
<p><i>Note: By using the &#8216;dot&#8217; in ["a".post in "b"] we are no longer using an &#8216;operator&#8217;. Explicit method calls are referred to as &#8220;function applications&#8221; in the reference</i></p>
<p>According to the <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf">Scala Reference</a>:</p>
<ul>
<li>If there are several infix operations, operators with higher precedence bind more closely than operators with lower precedence</li>
<li>If there are consecutive infix operations with operators of the same precedence, all operators must have the same associativity</li>
<li>Postfix operators always have lower precedence than infix operators</li>
</ul>
<p>While prefix operators aren&#8217;t mentioned, they appear to have a higher precedence than infix operators via experimentation:</p>
<pre class="brush: scala;">
scala&gt; class MyObj(val v : String) {
     | def +(m : MyObj)  = {println(&quot;[&quot; + v + &quot;.in(&quot; + m.v + &quot;)]&quot;); new MyObj(v + m.v) }
     | def unary_+ = {println(&quot;[&quot; + v + &quot;.pre()]&quot;); this}
     | }
defined class MyObj

scala&gt; implicit def stringToMyObj(s : String) : MyObj = new MyObj(s);
stringToMyObj: (s: String)MyObj

scala&gt; +&quot;a&quot; + +&quot;b&quot;
[a.pre()]
[b.pre()]
[a.in(b)]
res21: MyObj = MyObj@144f1ada
</pre>
<p>The end result of this discussion is another compromise. After experimenting with various notations, I gave up and returned to my original plan of a &#8220;!&#8221; method on an object returned by &#8220;SEEZ&#8221;:</p>
<pre class="brush: scala;">
scala&gt; class Printable(output:String) {
     | def ! = { print(output); }
     | def !! = { println(output); }
     | }
defined class Printable

scala&gt; class OutputStream {
     | def SEEZ(output: String) : Printable = new Printable(output)
     | }
defined class Printable

scala&gt; val U = new OutputStream
U: OutputStream = OutputStream@608d116e

scala&gt; U SEEZ &quot;Hello World&quot;!
Hello World
scala&gt; U SEEZ &quot;Hello World&quot;!!
Hello World

scala&gt;
</pre>
<p>Stay tuned, next time we&#8217;ll attempt to put the pieces together and run HelloLol.scala</p>
<hr /><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/scalearning_5_dsl_exploration_operation_precedence.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F11%2Fscalearning-5-dsl-exploration-operation-precedence%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/253/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=253&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/05/11/scalearning-5-dsl-exploration-operation-precedence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>ScaLearning 4 &#8211; DSL Exploration &amp; Operator Notation</title>
		<link>http://codequirks.com/2011/05/09/scalearning-4-dsl-exploration-and-operator-notation/</link>
		<comments>http://codequirks.com/2011/05/09/scalearning-4-dsl-exploration-and-operator-notation/#comments</comments>
		<pubDate>Mon, 09 May 2011 17:48:59 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[dsl exploration]]></category>
		<category><![CDATA[lolcode]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[ScaLearning]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=240</guid>
		<description><![CDATA[Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala. &#160; “ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing,&#160;&#8230; <a href="http://codequirks.com/2011/05/09/scalearning-4-dsl-exploration-and-operator-notation/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=240&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/0VGn1" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/r/scalearning_4_dsl_exploration_operator_notation.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala.<br />
&nbsp;<br />
“ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or otherwise worthy of talking about.<br />
&nbsp;<br />
&nbsp;</p>
<h3>Why make a DSL?</h3>
<p>I&#8217;ve heard it said that the real meat of learning Scala is done by people who want to expose a DSL. So far I&#8217;ve found learning Scala fairly easy. Sometimes I&#8217;m a little unclear on rules, like when I can leave out brackets and when I can&#8217;t, but when that happens I can just re-add the brackets and carry on.<br />
&nbsp;<br />
The same flexibility isn&#8217;t quite so true for people who wish to create a good DSL. A great deal of effort goes into carefully constructing the syntax. Scala is such an incredibly extensible language that, with a little patience, you can create code that doesn&#8217;t look at all like &#8220;Scala&#8221;, and yet still compiles.<br />
&nbsp;<br />
In order to get a taste of this learning, I decided I was going to attempt a DSL.<br />
&nbsp;<br />
&nbsp;</p>
<h3>Starting into DSL Exploration</h3>
<p>I decided my DSL of choice was going to be <a href="http://lolcode.com/">LOLCode</a>.<br />
&nbsp;<br />
Based on the (priceless) LolCats meme, LolCode presented itself as the perfect project to build a DSL around:</p>
<ul>
<li>Some rigidity in sticking close to the community consensus on syntax</li>
<li>Enough flexibility to allow me to explore a few different approaches</li>
<li>Different enough from Scala to present a challenge in implementation</li>
<li>There&#8217;s a specific &#8220;feel&#8221; for the DSL we can aim for</li>
<p>&nbsp;<br />
&nbsp;</p>
<h3>Learned Lesson 1: Operator Notation</h3>
<p>I decided to start where everyone starts, &#8220;Hello World&#8221;. System output is one of the most basic pieces of functionality for a language. The spec lists &#8220;VISIBLE&#8221; as the keyword for println:<br />
<code>VISIBLE "Hello World" // Prints hello world with a newline<br />
VISIBLE "Goodbye"! // Prints goodbye, but with no newline<br />
</code><br />
&nbsp;<br />
This seemed easy enough. We&#8217;ll start by ignoring the bang-syntax:<br />
<code>scala&gt; def VISIBLE(text : String) = {println(text)}<br />
VISIBLE: (text: String)Unit<br />
&nbsp;<br />
scala&gt; VISIBLE "Hello World"<br />
:1: error: ';' expected but string literal found.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VISIBLE "Hello World"<br />
</code><br />
&nbsp;<br />
Uh-oh.<br />
&nbsp;<br />
Just starting in, we&#8217;ve already ran into a lesson on operator syntax. There are three kinds of Operator Notation:</p>
<ul>
<li>Unary (prefix) Notation
<ul>
<li>Only works for +, -, !, and ~</li>
<li>Method must be no-args</li>
<li>Must omit the dot &#8211; ie: !.true would not work, but !true would</li>
</ul>
</li>
<li>Postfix Notation
<ul>
<li>Method must be no-args</li>
<li>May omit the dot and brackets if desired, but not required.</li>
</ul>
</li>
<li>Infix Notation
<ul>
<li>Method must be single-argument</li>
<li>May omit the dot and brackets if desired, but not required. ie: &#8220;a&#8221; + &#8220;b&#8221; or &#8220;a&#8221;.+(&#8220;b&#8221;)</li>
</ul>
</li>
</ul>
<p>&nbsp;<br />
In my case, &#8220;VISIBLE&#8221; would be a good Unary operator on some string-like object, but it is not a valid unary operator. For it to be an infix operator, I need some other &#8220;object&#8221; for it to be Infix of. Looks like I&#8217;ll have to compromise on this one.<br />
&nbsp;<br />
Reading around the site, I discovered that while the spec listed &#8220;VISIBLE&#8221; as the &#8220;println&#8221; equivalent, &#8220;U SEEZ&#8221; was the community&#8217;s preference.<br />
&nbsp;<br />
<code>U SEEZ "Hello World"<br />
U SEEZ "Hello World"!<br />
</code><br />
&nbsp;<br />
This is convenient, as commenters on LolCode pointed out, as &#8220;U&#8221; can be seen as the I/O similar to Java&#8217;s &#8220;System.out&#8221;, and &#8220;SEEZ&#8221; is simply a &#8220;print&#8221; method on any output stream.<br />
&nbsp;<br />
So let&#8217;s wrap up today&#8217;s post with one last crack at the non-bang notation:<br />
<code>scala&gt; class OutputStream {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|   def SEEZ(output: String) = println(output);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| }<br />
defined class OutputStream<br />
&nbsp;<br />
scala&gt; val U = new OutputStream<br />
U: OutputStream = OutputStream@4be03c55<br />
&nbsp;<br />
scala&gt; U SEEZ "Hello World"<br />
Hello World<br />
</code><br />
&nbsp;<br />
Worked like a charm. Stay tuned, as I continue to explore the process behind creating a DSL, and what it reveals about the language.</p>
<hr /><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/0VGn1" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://www.dzone.com/links/r/scalearning_4_dsl_exploration_operator_notation.html" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F05%2F09%2Fscalearning-4-dsl-exploration-and-operator-notation%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/240/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=240&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/05/09/scalearning-4-dsl-exploration-and-operator-notation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>The Fallibility of Tests</title>
		<link>http://codequirks.com/2011/04/15/the-fallibility-of-tests/</link>
		<comments>http://codequirks.com/2011/04/15/the-fallibility-of-tests/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 20:30:31 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=226</guid>
		<description><![CDATA[Recently I posted about Test Flow and Method Contracts. The key takeaway was that we can use tests to prove the contracts our system lives up to. We all create a logical representation of our software in our minds in order to reason about it. Tests (either manual, or automatic) allow us to prove the&#160;&#8230; <a href="http://codequirks.com/2011/04/15/the-fallibility-of-tests/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=226&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/Itlfd" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://widgets.dzone.com/links/widgets/zoneit.html?t=1&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F&amp;title=The%20Fallibility%20of%20Tests&amp;description=A%20commentary%20on%20how%20test%20automation%20helps%20address%20the%20problem%20of%20human%20error%20in%20software%20testing" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F15%2Fthe-fallibility-of-tests%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Recently I posted about <a href="http://codequirks.com/2011/04/11/test-flow-and-method-contracts/">Test Flow and Method Contracts</a>. The key takeaway was that we can use tests to prove the contracts our system lives up to.</p>
<p>We all create a logical representation of our software in our minds in order to reason about it. Tests (either manual, or automatic) allow us to prove the rules of that representation to be true.</p>
<p>Today I&#8217;ll talk about what it means when there are mistakes in those tests. For the purposes of this discussion, &#8220;tests&#8221; may be manual or automatic, but examples are given in code for clarity.<br />
&nbsp;<br />
&nbsp;</p>
<h2>Test Fallacy vs Test Absence</h2>
<p>The first distinction I want to make is between incorrect tests, and missing tests. </p>
<p><b><u>Test Fallacy</u></b> is when a test exists, but creates a logical fallacy within our reasoning system.</p>
<p>For example:<br />
<code><br />
// {new Cache} r = cache.has(x) {r == false}<br />
@Test<br />
public void has_shouldReturnFalse_whenItemHasNotBeenAddedToCache() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;//setup<br />
&nbsp;&nbsp;&nbsp;&nbsp;Cache c = new Cache();<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//execute<br />
&nbsp;&nbsp;&nbsp;&nbsp;boolean b = c.has("random");<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//assert<br />
&nbsp;&nbsp;&nbsp;&nbsp;assertTrue(b);<br />
}<br />
</code></p>
<p>Clearly the code disagrees with the test name. Since the name of the test is more likely to correspond to the rule I have in my head that I believe the system follows, this test could be extremely destructive to my system.<br />
&nbsp;<br />
&nbsp;<br />
<b><u>Test Absence</u></b> is when a test is absent, but we assume behaviour anyways. This is a logical mistake on our part, but it leads to bugs in the system.</p>
<p>I gave an example of this in my post <a href="http://codequirks.com/2011/04/11/test-flow-and-method-contracts/">Test Flow and Method Contracts</a> where we &#8220;forgot&#8221; to define the behaviour of &#8220;has&#8221; when the cache is empty.</p>
<p>The problem with test absence is that we often assume the behaviour exists, and is &#8220;reasonable&#8221; by our own subjective measure. That creates a problem &#8211; what is &#8220;reasonable&#8221;? &nbsp;<br />
&nbsp;</p>
<h2>The Danger of Test Fallibility</h2>
<p>While tests are fallible, either through a mistake or through absence, it&#8217;s useful to keep in mind why that is dangerous.</p>
<p>A professor for my logic class said something one class that stuck with me:</p>
<blockquote><p>
Logical fallacies don&#8217;t just create problems in logical systems, they destroy them. If you consider any false statement to be true, anything can be proven.</p>
<p>Let&#8217;s say, for example, that 2 = 3. I&#8217;ll prove I&#8217;m the Queen of England.</p>
<p>How? Well 3 &#8211; 2 = 1, but 3 &#8211; 3 = 0. Since 2 and 3 are equal, that implies 1 and 0 are equal.</p>
<p>Furthermore, 2 &#8211; 1 = 1, but 2 &#8211; 0 = 2. Since 1 and 0 are equal, so too are 1 and 2.</p>
<p>Now the Queen and I are, in fact, two distinct people. But 2 = 1, which means the Queen and I are one. So you see, I am in fact the Queen of England.<br />
<i>(Paraphrased from memory)</i>
</p></blockquote>
<p>Honestly, I probably would have chosen to prove I was Metallica (the entire band), but if one admits that 2 = 3, the rest of the logic is difficult to argue against. With one false &#8220;fact&#8221;, we destroyed our entire reasoning system.</p>
<p>I&#8217;m sure many of us can relate this back to software. Try to recall a time when you received a bug complaint from a user, and after tracking down the bug you stared in awe at your computer screen. &#8220;That shouldn&#8217;t even be possible&#8230;&#8221;</p>
<p>The real problem? These &#8220;glitches&#8221; in our reasoning systems are inevitable. We&#8217;re all humans, we will make a mistake. One way or another, you will eventually have a bug in a test, or assume behaviour exists that really doesn&#8217;t.<br />
&nbsp;<br />
&nbsp;</p>
<h2>How do we Address Test Fallibility?</h2>
<p>This brings me back around to the original topic &#8211; how do we avoid this fallibility?</p>
<p>We automate our test suite.</p>
<p>It seems strange to say automation will &#8220;cure&#8221; all of our problems reasoning about systems, and that&#8217;s because it won&#8217;t. It&#8217;s simply the best way to combat the problem.</p>
<p>Automation addresses <u>Test Absence</u> by:</p>
<ul>
<li>being cheaper (time) than manual testing</li>
<li>eliminating any reasons to skip tests</li>
<li>growing as a <u>regression suite</u> over time as we think of new test cases</li>
</ul>
<p>If you forget a test, simply add it and it will never be forgotten again.</p>
<p>Automation addresses <u>Test Fallacies</u> by:</p>
<ul>
<li>being repeatable</li>
<li>being correctable (you can&#8217;t prevent humans from re-making mistakes)</li>
<li>being easy to read, examine, and reason about</li>
</ul>
<p>If you make a mistake in a test, simply fix it and the mistake will not reoccur.</p>
<p>In summary, automating your tests doesn&#8217;t guarantee that your tests will be good, but it allows you to confidently improve your tests over time. Good test allow you to reason correctly about your system. </p>
<hr />
<a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/Itlfd" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://widgets.dzone.com/links/widgets/zoneit.html?t=1&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F&amp;title=The%20Fallibility%20of%20Tests&amp;description=A%20commentary%20on%20how%20test%20automation%20helps%20address%20the%20problem%20of%20human%20error%20in%20software%20testing" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F15%2Fthe-fallibility-of-tests%2F15%2Fthe-fallibility-of-tests%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/226/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=226&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/04/15/the-fallibility-of-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>ScaLearning 3 &#8211; Is Scala Hard to Learn?</title>
		<link>http://codequirks.com/2011/04/14/scalearning-3-is-scala-hard-to-learn/</link>
		<comments>http://codequirks.com/2011/04/14/scalearning-3-is-scala-hard-to-learn/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 21:48:22 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[ScaLearning]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=199</guid>
		<description><![CDATA[Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala. “ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or&#160;&#8230; <a href="http://codequirks.com/2011/04/14/scalearning-3-is-scala-hard-to-learn/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=199&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/16mjo" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://widgets.dzone.com/links/widgets/zoneit.html?t=1&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F&amp;title=ScaLearning%203-%20Is%20Scala%20Hard%20to%20Learn&amp;description=A%20look%20back%20at%20how%20difficult%20Scala%20was%20to%20learn%20so%20far" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala.</p>
<p>“ScaLearning” will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or otherwise worthy of talking about.<br />
&nbsp;<br />
&nbsp;</p>
<h3>Is Scala Hard to Learn?</h3>
<p>If you want to skip the explanation, my answer is no.</p>
<p>To elaborate, I&#8217;ve heard a great deal of &#8220;buzz&#8221; about how complicated Scala is. I&#8217;ve heard it said that it will become an academic language, and that average programmers won&#8217;t be able to pick it up. Unfortunately, the blogosphere is so cluttered with rebuttals to the idea that it&#8217;s hard to find anyone actually critiquing Scala.</p>
<blockquote><p>
Some examples of pro-scala posts:</p>
<p><a href="http://lamp.epfl.ch/~odersky/blogs/isscalacomplex.html">Is Scala Complex?</a> (Martin Odersky)<br />
<a href="http://blog.ericdaugherty.com/2010/07/is-scala-too-complex.html">Is Scala Too Complex?</a> (Eric Daugherty)<br />
<a href="http://speaking-my-language.blogspot.com/2009/11/is-scala-more-complicated-than-java.html">Is Scala More Complicated than Java?</a> (Vassil Dichev)</p>
<p>Some examples critiquing the complexity:</p>
<p><a href="http://creativekarma.com/ee.php/weblog/comments/my_verdict_on_the_scala_language/">My Verdict on the Scala Language</a> (Doug Pardee)<br />
<a href="http://stackoverflow.com/questions/1722726/is-the-scala-2-8-collections-library-a-case-of-the-longest-suicide-note-in-histo/1728140">Is the Scala 2.8 Collections Library a Case of the Longest Suicide Note in History?</a> (oxbow_lakes)
</p></blockquote>
<p>Since a lot has been said already, I won&#8217;t go into any in-depth tirade about software complexity. I will, however, draw on my experience:</p>
<p>For me, Scala has been easy to learn after a few years of Java because:</p>
<ul>
<li>Type system that&#8217;s similar to Java</li>
<li>Java interoperability allows me to ease myself in</li>
<li>It&#8217;s possible to write near-Java syntax, and have it be valid Scala</li>
<li>Many Scala keywords have direct analogs in Java (ie: <i>public final String s</i> vs <i>val s : String</i></li>
</ul>
<p>&nbsp;<br />
&nbsp;<br />
So far I&#8217;ve done two &#8220;projects&#8221; in Scala. </p>
<p>One was a <a href="http://www.liftweb.net">Lift</a> (version 1.x) application that talked to a back-end set of <a href="http://jersey.java.net/">Jersey</a> services. The native XML handling was a dream-come-true, but the mapping of Lift 1.0 made me think Scala was much harder than it is.</p>
<p>The second project was an experimental conversion of a Spring MVC application using JSP views into a Lift 2.x website. I left the backing services in Java, used Spring to get the dependencies, but rewrote the front-end to be Lift. The mapping I hated in 1.x had been completely overhauled, and was actually very pleasant to work with.<br />
&nbsp;<br />
&nbsp;<br />
That brings me to the take-away of this post.<br />
&nbsp;<br />
&nbsp;<br />
A large part of the &#8220;complexity&#8221; people see in Scala isn&#8217;t the language. It&#8217;s the libraries and frameworks.</p>
<p>Scala, as a language, is very simple and very powerful. Overall, while I don&#8217;t know every feature, I feel as if I know enough to be able to understand most of the code I read, and colleagues familiar with Scala seem to be able to read the code I&#8217;m writing.</p>
<p>I find Scala very easy to learn. Some libraries have been a challenge&#8230; but then, so is learning the exact magic incantation for Java&#8217;s file IO.</p>
<hr /><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/16mjo" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://widgets.dzone.com/links/widgets/zoneit.html?t=1&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F&amp;title=ScaLearning%203-%20Is%20Scala%20Hard%20to%20Learn&amp;description=A%20look%20back%20at%20how%20difficult%20Scala%20was%20to%20learn%20so%20far" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F14%2Fscalearning-3-is-scala-hard-to-learn%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=199&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/04/14/scalearning-3-is-scala-hard-to-learn/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
		<item>
		<title>ScaLearning 2 &#8211; Reducing string-join to a line</title>
		<link>http://codequirks.com/2011/04/13/scalearning-2-reducing-string-join-to-a-line/</link>
		<comments>http://codequirks.com/2011/04/13/scalearning-2-reducing-string-join-to-a-line/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 16:29:32 +0000</pubDate>
		<dc:creator>criassk</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[ScaLearning]]></category>

		<guid isPermaLink="false">http://codequirks.com/?p=177</guid>
		<description><![CDATA[Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala. &#8220;ScaLearning&#8221; will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or&#160;&#8230; <a href="http://codequirks.com/2011/04/13/scalearning-2-reducing-string-join-to-a-line/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=177&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/D5Sic" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://widgets.dzone.com/links/widgets/zoneit.html?t=1&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F&amp;title=ScaLearning%202-%20Reducint%20string-join%20to%20a%20line&amp;description=Commentary%20on%20the%20benefit%20of%20fewer%20more%20readable%20lines%20with%20an%20example" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a><br />
<hr />
Like many developers who make the journey from Java to Scala, I often find myself amazed at how much easier it is to do some things, or how much easier it is to express myself in Scala.</p>
<p>&#8220;ScaLearning&#8221; will be a series of short blog-posts just documenting little tidbits I find interesting, confusing, amusing, or otherwise worthy of talking about.</p>
<h3>String Joining</h3>
<p>I recently found myself writing a SQL generator that took a domain-specific query object and turned it into raw SQL. We had to write our own, as we needed to optimize several parts of the query, or face the rage of the customer when things were a little sluggish.</p>
<p>(It&#8217;s generally bad for business when the customer goes Hulk on you.)</p>
<p>As happens often in generating SQL, I found myself wanting to store a list and later convert it into a comma-separated string. </p>
<p><u>Java &#8211; First Attempt</u><br />
<code><br />
StringBuilder result = new StringBuilder();<br />
List items = Arrays.asList("a", "b", "c", "d");<br />
boolean first = true;<br />
for(String i : items) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if(first) first = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;else result.append(", ");<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;result.append(i);<br />
}<br />
System.out.println(result.toString());<br />
</code></p>
<p>Sloppy. Three lines in the for loop, a local variable hanging around. It&#8217;s readable, but having to read 5-7 lines just to realize it&#8217;s a string-join seems excessive. Try again!</p>
<p><u>Java &#8211; Second Attempt</u><br />
<code><br />
StringBuilder result = new StringBuilder();<br />
List items = Arrays.asList("a", "b", "c", "d");<br />
for(String i : items) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;result.append(", ").append(i);<br />
}<br />
System.out.println(result.toString().replaceFirst(", ", ""));<br />
</code></p>
<p>Shorter, no local variable, but now we&#8217;re doing &#8220;unwork&#8221; to get rid of the leading comma. That&#8217;s an easy detail to miss, so fewer lines but not much more readable.</p>
<p><i>(I&#8217;m open to cleaner implementations! Comment with what you prefer.)</i></p>
<p><u>Scala</u></p>
<p>In Scala (and many other languages, ie: PHP) this is a simple one-liner.</p>
<p><code><br />
val items = List("a", "b", "c", "d");<br />
println( items.reduceLeft(_ + ", " + _) )<br />
println( items.mkString(", ") )<br />
</code></p>
<p>Two ways, both one line. Both are readable, and I don&#8217;t have a real preference between them.</p>
<p>While readability and line count aren&#8217;t always so tied, the fewer lines a person has to read the faster they can read them. While I could easily write a method for Java to join Strings, this is just another example of how Scala seems to actively try to make my life easier.</p>
<hr />
<a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/facebook.png?w=48&#038;h=48" alt="facebook" height="48" width="48" border="0"></a><a href="http://clicktotweet.com/D5Sic" target="_blank"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/twitter.png?w=48&#038;h=48" alt="twitter" height="48" width="48" border="0"></a><a target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F"><img style="margin-right:10px;" src="http://kodequirks.files.wordpress.com/2010/05/digg.png?w=48&#038;h=48" alt="digg" height="48" width="48" border="0"></a><a href="http://widgets.dzone.com/links/widgets/zoneit.html?t=1&amp;url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F&amp;title=ScaLearning%202-%20Reducint%20string-join%20to%20a%20line&amp;description=Commentary%20on%20the%20benefit%20of%20fewer%20more%20readable%20lines%20with%20an%20example" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/dzone.png?w=48&#038;h=48" alt="dzone" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png?w=48&#038;h=48" alt="stumbleupon" style="margin-right:10px;" height="48" width="48" border="0"></a><a target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F"><img src="http://kodequirks.files.wordpress.com/2010/05/reddit.png?w=48&#038;h=48" alt="reddit" style="margin-right:10px;" height="48" width="48" border="0"></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fcodequirks.com%2F2011%2F04%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F13%2Fscalearning-2-reducing-string-join-to-a-line%2F" target="_blank"><img src="http://kodequirks.files.wordpress.com/2010/05/delicious.png?w=48&#038;h=48" alt="delicious" style="margin-right:10px;" height="48" width="48" border="0"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kodequirks.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kodequirks.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kodequirks.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kodequirks.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kodequirks.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kodequirks.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kodequirks.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kodequirks.wordpress.com/177/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codequirks.com&amp;blog=12777876&amp;post=177&amp;subd=kodequirks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codequirks.com/2011/04/13/scalearning-2-reducing-string-join-to-a-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/40eb33ebd3a0903f27c2ae55da519d20?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">criassk</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/facebook.png" medium="image">
			<media:title type="html">facebook</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/twitter.png" medium="image">
			<media:title type="html">twitter</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/digg.png" medium="image">
			<media:title type="html">digg</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/dzone.png" medium="image">
			<media:title type="html">dzone</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/stumbleupon.png" medium="image">
			<media:title type="html">stumbleupon</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/reddit.png" medium="image">
			<media:title type="html">reddit</media:title>
		</media:content>

		<media:content url="http://kodequirks.files.wordpress.com/2010/05/delicious.png" medium="image">
			<media:title type="html">delicious</media:title>
		</media:content>
	</item>
	</channel>
</rss>
