<?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>Mawson's Hut</title>
	<atom:link href="http://mawson.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mawson.wordpress.com</link>
	<description>Welcome to the Antarctic of the Internet (see it before it melts).</description>
	<lastBuildDate>Mon, 07 Jun 2010 02:15:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mawson.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Mawson's Hut</title>
		<link>http://mawson.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mawson.wordpress.com/osd.xml" title="Mawson&#039;s Hut" />
	<atom:link rel='hub' href='http://mawson.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Mawson&#8217;s Hut at Posterous</title>
		<link>http://mawson.wordpress.com/2010/06/07/mawsons-hut-at-posterous/</link>
		<comments>http://mawson.wordpress.com/2010/06/07/mawsons-hut-at-posterous/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 02:15:36 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/?p=148</guid>
		<description><![CDATA[Recently I&#8217;ve added some half-completed posts here. These were published via Posterous and did not render correctly on WordPress. I have removed the auto-post from Posterous to here, as no post is better than a broken post. My posterous blog is synesso.posterous.com<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=148&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;ve added some half-completed posts here. These were published via Posterous and did not render correctly on WordPress. I have removed the auto-post from Posterous to here, as no post is better than a broken post.</p>
<p>My posterous blog is <a href="http://synesso.posterous.com/">synesso.posterous.com</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=148&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2010/06/07/mawsons-hut-at-posterous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Bradford Cross on Lean</title>
		<link>http://mawson.wordpress.com/2010/06/03/bradford-cross-on-lean/</link>
		<comments>http://mawson.wordpress.com/2010/06/03/bradford-cross-on-lean/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 00:12:38 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/2010/06/03/bradford-cross-on-lean/</guid>
		<description><![CDATA[There&#039;s an excellent article from Bradford Cross today on Lean.  http://measuringmeasures.com/blog/2010/6/2/looking-back-at-lean-6-lessons-for-winning.html   I particularly like the following bits: Iteration boundaries can be handy management reporting milestones but they do not need to concern the card wall of a lean team Retrospectives are ad hoc &#8211; ongoing collection via walls, conduct retro when wall is full. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=142&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div class='posterous_autopost'>
<div style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;">
<div>There&#039;s an excellent article from Bradford Cross today on Lean. </div>
<p />
<div>
<div style="font-family:Arial;font-size:small;"><a href="http://measuringmeasures.com/blog/2010/6/2/looking-back-at-lean-6-lessons-for-winning.html" target="_blank" style="color:rgb(42,93,176);">http://measuringmeasures.com/blog/2010/6/2/looking-back-at-lean-6-lessons-for-winning.html</a></div>
</div>
<div> </div>
<div>I particularly like the following bits:</div>
<ul>
<li style="margin-left:15px;">Iteration boundaries can be handy management reporting milestones but they do not need to concern the card wall of a lean team</li>
<li style="margin-left:15px;">Retrospectives are ad hoc &#8211; ongoing collection via walls, conduct retro when wall is full. - <em>what a great idea, we&#039;re going to implement this in my current team right now.</em></li>
<li style="margin-left:15px;">If your chunks of work are more than 2 days, you are doing it wrong. - <em>where &#039;doing it wrong&#039; might mean &#039;working with a cumbersome codebase that needs refactoring&#039; *wink*</em></li>
<li style="margin-left:15px;">Automated QA test scripts are the created by the team, not just a QA &#8211; <i>or perhaps your team is staffed with people who are BA/Dev/QA material all rolled into one.</i></li>
<li style="margin-left:15px;"><em>Finger charts for finding bottlenecks - <a href="http://epistemologic.com/2007/10/02/lean-software-development-how-to-find-bottlenecks-metrics-that-matter/" target="_blank" style="color:rgb(42,93,176);">http://epistemologic.com/2007/10/02/lean-software-development-how-to-find-bottlenecks-metrics-that-matter/</a></em></li>
</ul>
<p /></div>
<p style="font-size:10px;">  <a href="http://posterous.com">Posted via email</a>   from <a href="http://synesso.posterous.com/bradford-cross-on-lean">Mawson&#8217;s Hut</a>  </p>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=142&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2010/06/03/bradford-cross-on-lean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the scala logo.</title>
		<link>http://mawson.wordpress.com/2010/05/07/using-the-scala-logo/</link>
		<comments>http://mawson.wordpress.com/2010/05/07/using-the-scala-logo/#comments</comments>
		<pubDate>Fri, 07 May 2010 02:00:33 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/2010/05/07/using-the-scala-logo/</guid>
		<description><![CDATA[I inquired about the use of the Scala logo for the Scala Twibbon. The logo is proprietary after all. This is the reply I received (in the context of the Twibbon):     &#34;The Scala logo is a trademark of EPFL. In principle we reserve all rights to the logo, but we are happy to authorize its use for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=141&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div class='posterous_autopost'><span style="border-collapse:collapse;">I inquired about the use of the Scala logo for the <a href="http://twibbon.com/cause/Scala/">Scala Twibbon</a>. The logo is proprietary after all. This is the reply I received (in the context of the Twibbon):</span>
<div> <span style="border-collapse:collapse;"><br /></span><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;">    &quot;The Scala logo is a trademark of EPFL. In principle we reserve all rights to the logo, but we are happy to authorize its use for any legitimate Scala-related application.&quot;</span><br /> <span style="border-collapse:collapse;"><br /></span><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;">    So the use of the logo for twibbon is absolutely fine. In general we tend to use the Scala logo in two forms: <a href="http://lampsvn.epfl.ch/images/Scala_Logo2008.png">one with three &quot;twirls&quot; and the Scala name on the side</a>, or, </span><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;">when no name is used, we normally use <a href="http://image.spreadshirt.net/image-server/image/configuration/21949725/producttypecolor/1/type/png/width/280/height/280">just two &quot;twirls&quot;</a> to obtain a square icon.</span></div>
<p style="font-size:10px;">  <a href="http://posterous.com">Posted via email</a>   from <a href="http://synesso.posterous.com/using-the-scala-logo">Beavious Grodily Harm</a>  </p>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=141&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2010/05/07/using-the-scala-logo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Running JUnit tests in SBT</title>
		<link>http://mawson.wordpress.com/2010/04/09/running-junit-tests-in-sbt/</link>
		<comments>http://mawson.wordpress.com/2010/04/09/running-junit-tests-in-sbt/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 06:56:19 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/2010/04/09/running-junit-tests-in-sbt/</guid>
		<description><![CDATA[With Simple Build Tool v0.7.3 it is now possible to find and execute JUnit tests without modifying them. It requires a patched version of junit-interface to be included as a test dependency. Here&#39;s how: Until there&#39;s a version 0.4 of junit-interface, get v0.3 from http://github.com/szeiger/junit-interface   wget http://github.com/szeiger/junit-interface/tarball/0.3   tar zxf szeiger-junit-interface-6671824.tar.gz   cd szeiger-junit-interface-6671824/ Get and apply the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=140&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div class='posterous_autopost'>
<div>With Simple Build Tool v0.7.3 it is now possible to find and execute JUnit tests without modifying them. It requires a patched version of junit-interface to be included as a test dependency. Here&#39;s how:</div>
<p />
<div>Until there&#39;s a version 0.4 of junit-interface, get v0.3 from <a href="http://github.com/szeiger/junit-interface" target="_blank">http://github.com/szeiger/junit-interface</a></div>
<div>
<div>  wget <a href="http://github.com/szeiger/junit-interface/tarball/0.3" target="_blank">http://github.com/szeiger/junit-interface/tarball/0.3</a></div>
</p></div>
<div>  tar zxf szeiger-junit-interface-6671824.tar.gz</div>
<div>
<div>  cd szeiger-junit-interface-6671824/</div>
</div>
<p />
<div>Get and apply the patch that will enable this to find native JUnit @Test annotations. Download szeiger_junit_interface_0.5.patch from <a href="http://groups.google.com/group/simple-build-tool/files">http://groups.google.com/group/simple-build-tool/files</a> and save as &#39;patch&#39;. Then execute</div>
<div>
<div>
<div>  git apply patch</div>
</div>
</div>
<p />
<div>Build and publish junit interface locally.</div>
<div>  sbt clean update publish-local</div>
<p />
<div>Add the following line to the project definition for your project</div>
<div>
<div>  val junitInterface = &quot;com.novocode&quot; % &quot;junit-interface&quot; % &quot;0.4&quot; % &quot;test&quot;</div>
</div>
<p />
<div>Follow up with</div>
<div>  sbt clean update test</div>
<p />
<div>Provided you are on 0.7.3 of SBT, tests marked with the JUnit @Test annotation will have been executed.</div>
<p style="font-size:10px;">  <a href="http://posterous.com">Posted via email</a>   from <a href="http://synesso.posterous.com/running-junit-tests-in-sbt">Beavious Grodily Harm</a>  </p>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/140/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=140&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2010/04/09/running-junit-tests-in-sbt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Someone sent me photos of baby hedgehogs &#8230;</title>
		<link>http://mawson.wordpress.com/2009/11/06/photos-of-hedgehogs/</link>
		<comments>http://mawson.wordpress.com/2009/11/06/photos-of-hedgehogs/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 04:15:38 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/2009/11/06/someone-sent-me-photos-of-more-baby-echidnas/</guid>
		<description><![CDATA[See and download the full gallery on posterous &#160; Posted via email from Beavious Grodily Harm<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=138&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img src="http://posterous.com/getfile/files.posterous.com/jeremy-eyinr/oJGEwvccgUsGEBpp2WfRwx9nEXr8AbfRMFQeiIqA22SrinPey3CFKka8lDSD/image004_9.jpg" alt="" width="480" /> <img src="http://posterous.com/getfile/files.posterous.com/jeremy-eyinr/aU86Tjh5gVf4ZMAxLmV5J1wbxZHupTmJUJejqK9WAhwuq4pZzeBEBvA5owoj/image002_11.jpg" alt="" width="480" /></p>
<div><a href="http://synesso.posterous.com/someone-sent-me-photos-of-more-baby-echidnas">See and download the full gallery on posterous</a></div>
<p>&nbsp;</p>
<p style="font-size:10px;"><a href="http://posterous.com">Posted via email</a> from <a href="http://synesso.posterous.com/someone-sent-me-photos-of-more-baby-echidnas">Beavious Grodily Harm</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=138&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2009/11/06/photos-of-hedgehogs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>

		<media:content url="http://posterous.com/getfile/files.posterous.com/jeremy-eyinr/oJGEwvccgUsGEBpp2WfRwx9nEXr8AbfRMFQeiIqA22SrinPey3CFKka8lDSD/image004_9.jpg" medium="image" />

		<media:content url="http://posterous.com/getfile/files.posterous.com/jeremy-eyinr/aU86Tjh5gVf4ZMAxLmV5J1wbxZHupTmJUJejqK9WAhwuq4pZzeBEBvA5owoj/image002_11.jpg" medium="image" />
	</item>
		<item>
		<title>Using Scala to replace a Rake task</title>
		<link>http://mawson.wordpress.com/2009/09/18/using-scala-to-replace-a-rake-task/</link>
		<comments>http://mawson.wordpress.com/2009/09/18/using-scala-to-replace-a-rake-task/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 03:03:34 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[geospatial]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scweery]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/?p=123</guid>
		<description><![CDATA[Reimplementing a Rake task in Scala improved performance by at least 50x<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=123&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>At work we recently completed a task to generate a datafile of locations mapped to nearby locations. Our input is a Postgres table of location data, including name, latitude and longitude. Our target output is a YAML file of each location mapped to those locations which are geographically close.</p>
<p>With the <a href="http://postgis.refractions.net/">PostGIS</a> extension, <a href="http://www.postgresql.org/">PostgreSQL</a> has excellent support for calculating the distance between locations, so our calculations were delegated to the SQL queries. Essentially the query joined each location with every other location and excluded those which exceeded our distance threshold (for example, 25,000 metres).</p>
<p>The task was implemented in Rake. The execution time was in the order of 8 hours. It was assumed that the majority of time was needed for Postgres to perform the GIS calculations. Not so.</p>
<p>I reimplemented the task in Scala using <a href="http://github.com/Synesso/scweery">Scweery</a>. The Scala version differs from the rake task in several ways. It is strongly typed (as necessitated by the language) and, apart from IO operations, purely functional (my personal preference). It also used JDBC instead of ActiveRecord. Apart from these differences the algorithm is identical to its Ruby counterpart.</p>
<p>So did the Scweery/Scala version outperform Rake? Yes, without a doubt. /usr/bin/time reports that the Scala version was completed in 8m, 55s. That&#8217;s at least 50 times quicker. Importantly, it turns what was an overnight task into what is now a coffee break task.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=123&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2009/09/18/using-scala-to-replace-a-rake-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Building the chesspiece movement DSL (Scala)</title>
		<link>http://mawson.wordpress.com/2009/04/26/building-the-chesspiece-movement-dsl-scala/</link>
		<comments>http://mawson.wordpress.com/2009/04/26/building-the-chesspiece-movement-dsl-scala/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 12:32:33 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[scalacheck]]></category>
		<category><![CDATA[specs]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/?p=98</guid>
		<description><![CDATA[My latest objective has been to construct a DSL for asserting whether a chess piece, within the context of a game, can make a particular move. I have managed to construct a syntax that resembles: pawn canMove Straight towards Black Some alternative examples are : pawn canMove Straight by 2 towards Black pawn canMove Diagonally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=98&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>My latest objective has been to construct a DSL for asserting whether a chess piece, within the context of a game, can make a particular move. I have managed to construct a syntax that resembles:</p>
<pre><span style="color:#008000;">pawn canMove Straight towards Black</span></pre>
<p>Some alternative examples are :</p>
<pre><span style="color:#008000;">pawn canMove Straight by 2 towards Black</span></pre>
<pre><span style="color:#008000;">pawn canMove Diagonally towards (Black, King)</span></pre>
<p>With this syntax it is possible to construct executable specifications using Specs that read:</p>
<pre><span style="color:#ff6600;">"a pawn that has already been moved and is not blocked"</span> <span style="color:#333399;">should</span> {
    <span style="color:#ff6600;">"be able to move one square towards opposite colour"</span> <span style="color:#333399;">in</span> {
      <span style="color:#008000;">pawn canMove Straight towards Black must beTrue</span>
    }
}</pre>
<p>Operator notation is what enables the building of this kind of syntax. It is the ability to omit the dot and parentheses on any function call with exactly one parameter. It is not possible to achieve this when there is 2 or more parameters (both dot and parentheses are required) or when there are zero (the parentheses are optional, but the dot is required).</p>
<p>Without operator notation, the initial example above would be written as:</p>
<pre><span style="color:#008000;">  pawn.canMove(Straight).towards(Black)</span></pre>
<h3>Straight-line movement</h3>
<p>In order to facilitate this structure, Piece.canMove(m: Movement) implies an instance of CanMove (a case class). CanMove.towards(o: Orientation) decides whether the move can proceed. Both Straight and Black are case objects.</p>
<pre><span style="color:#333399;">class</span> Piece(<span style="color:#333399;">val</span> colour: <span style="color:#993366;">Colour</span>, <span style="color:#333399;">val</span> role: <span style="color:#993366;">Role</span>, <span style="color:#333399;">val</span> position: <span style="color:#993366;">Position</span>) {
  <span style="color:#333399;">def</span> canMove[M &gt;: <span style="color:#993366;">Movement</span>](m: M): CanMove[M] = CanMove(m, <span style="color:#333399;">this</span>)
}

<span style="color:#333399;">case class</span> CanMove[M &gt;: <span style="color:#993366;">Movement</span>](m: M, p: <span style="color:#993366;">Piece</span>) {
  <span style="color:#333399;">var</span> dist = 1
  <span style="color:#333399;">def</span> towards(o: <span style="color:#993366;">Orientation</span>): <span style="color:#993366;">Boolean</span> = {
    m <span style="color:#333399;">match</span> {
      <span style="color:#333399;">case</span> <span style="color:#993366;">Straight</span> =&gt; p.role <span style="color:#333399;">match</span> {
        <span style="color:#333399;">case</span> <span style="color:#993366;">Pawn</span> =&gt; dist == 1 &amp;&amp; o.equals(opposite of p.colour)
        <span style="color:#333399;">case</span> _ =&gt; <span style="color:#333399;">false</span>
      }
      <span style="color:#333399;">case</span> _ =&gt; <span style="color:#333399;">false</span>
    }
  }
}</pre>
<p>At this stage, only the behaviour for &#8220;a pawn that has already been moved and is not blocked&#8221; has been specified. As such it is a simple case statement. If the movement is Straight and the piece is a Pawn, check that it is trying to move 1 space and that it is moving toward the opposite coloured side.</p>
<h3>Diagonal Movement</h3>
<p>Queries regarding diagonal movement require additional thought, as the direction is a composite of both Colour (Black or White) and Role with Orientation (Queen or King). In this case, a towards function is provided that takes a Tuple2 of these two parameters.</p>
<pre><span style="color:#333399;">def</span> towards(o: <span style="color:#993366;">Tuple2</span>[<span style="color:#993366;">Colour</span>, <span style="color:#993366;">Role</span> <span style="color:#333399;">with</span> <span style="color:#993366;">Orientation</span>]): <span style="color:#993366;">Boolean</span> = <span style="color:#333399;">false</span></pre>
<p>The function currently returns false, because there is no specification written yet that would require it to be true. Following BDD means the simplest possible implementation that would work is in place.</p>
<p>Using a Tuple2 instead of two input parameters permits operator notation to be used. That is, it is a single parameter comprised of two values. Although denoting the tuple does require the use of parentheses and a comma, but I think the effect is still readable.</p>
<pre><span style="color:#ff6600;">"a pawn that has already been moved and is not blocked"</span> <span style="color:#333399;">should</span> {
  <span style="color:#ff6600;">"not be able to move diagonally towards black queen"</span> <span style="color:#333399;">in</span> {
    <span style="color:#008000;">pawn canMove Diagonally towards (Black, Queen) must beFalse</span>
  }
}</pre>
<h3>Movement greater than 1 square</h3>
<p>In order to support movement in a direction over multiple squares, the CanMove class is provided a by(distance: Int) function that sets the distance on the instance, and returns the instance again for a chained function call.</p>
<pre><span style="color:#000080;">def</span> by(distance: <span style="color:#800080;">Int</span>) = {
  <span style="color:#008000;">dist</span> = distance
  <span style="color:#000080;">this</span>
}</pre>
<p>This permits the interspersing of &#8216;by <em>n</em>&#8216; as an optional term. On the downside, it also permits the illogical interspersing of multiple calls to &#8216;by <em>n</em>&#8216;. Such as:</p>
<pre><span style="color:#008000;">pawn canMove Straight <strong>by 1 by 9 by 4</strong> towards Black</span></pre>
<p>The pawn movement specification for this function utilises <a href="http://code.google.com/p/scalacheck/">ScalaCheck </a>to test a range of conditions of <em>n</em> from 2 upwards. This testing tool executes the specification with 100 arbitrary values of <em>n</em> that are 2 or greater.</p>
<pre><span style="color:#ff6600;">"a pawn that has already been moved and is not blocked"</span> <span style="color:#000080;">should</span> {
 <span style="color:#ff6600;"> "not be able to move more than one square towards opposite colour"</span> <span style="color:#000080;">in</span> {
    <span style="color:#000080;">forAll</span> { n: <span style="color:#800080;">Int</span> =&gt; n &gt;= 2 ==&gt;
            (<span style="color:#008000;">pawn canMove Straight by n towards Black equals false</span>)
    } <span style="color:#000080;">must pass</span>
  }
}</pre>
<h3>Source code</h3>
<p>The complete code (as a work in progress) lives on <a href="http://github.com/Synesso/scala-chess/tree/master">github</a>. I welcome any advice on how to improve the approach I&#8217;ve taken.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=98&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2009/04/26/building-the-chesspiece-movement-dsl-scala/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency management in SBT</title>
		<link>http://mawson.wordpress.com/2009/04/26/dependency-management-in-sbt/</link>
		<comments>http://mawson.wordpress.com/2009/04/26/dependency-management-in-sbt/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 01:13:16 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/?p=92</guid>
		<description><![CDATA[This is an example of how easy it is to declare dependencies in a scala project using Simple Build Tool. import sbt._ class SpecsProject(info: ProjectInfo) extends DefaultProject(info) { val specsRepo = "Specs Repository" at "http://specs.googlecode.com/svn/maven2/" val specs = "org.scala-tools.testing" % "specs" % "1.4.4" val scalacheck = "org.scala-tools.testing" % "scalacheck" % "1.5" val mockito = "org.mockito" [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=92&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is an example of how easy it is to declare dependencies in a scala project using <a href="http://code.google.com/p/simple-build-tool/">Simple Build Tool</a>.</p>
<div style="border-width:1px;padding:5px;">
<pre>import sbt._
class SpecsProject(info: ProjectInfo) extends DefaultProject(info) {
  val specsRepo = "Specs Repository" at "http://specs.googlecode.com/svn/maven2/"

  val specs = "org.scala-tools.testing" % "specs" % "1.4.4"
  val scalacheck = "org.scala-tools.testing" % "scalacheck" % "1.5"
  val mockito = "org.mockito" % "mockito-core" % "1.7"
  val junit = "junit" % "junit" % "4.4"
}</pre>
</div>
<p>I love how Scala lets me code without being force-fed XML everywhere I turn.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=92&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2009/04/26/dependency-management-in-sbt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing the LoginSnippet</title>
		<link>http://mawson.wordpress.com/2009/04/12/testing-the-login-snippet/</link>
		<comments>http://mawson.wordpress.com/2009/04/12/testing-the-login-snippet/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 08:36:55 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/?p=65</guid>
		<description><![CDATA[In my previous post I included some code to get the currently logged-in user. This code was copy-and-pasted from the sample applications provided in the SDK. Let&#8217;s consider this previous code to be a prototype. Real software development should always be test-driven, otherwise it&#8217;s just an exercise in building legacy code. I&#8217;ve heard good things [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=65&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In my previous post I included some code to get the currently logged-in user. This code was copy-and-pasted from the sample applications provided in the SDK. Let&#8217;s consider this previous code to be a prototype. Real software development should always be test-driven, otherwise it&#8217;s just an exercise in building legacy code.</p>
<p>I&#8217;ve heard good things about two Scala based testing frameworks: <a href="http://www.artima.com/scalatest/">ScalaTest</a> and <a href="http://code.google.com/p/specs/">Specs</a>. After some investigation into both I&#8217;ve decided to run with Specs. I intend to test in a behavioural manner and so don&#8217;t need the flexibility of other testing styles that ScalaTest provides. In my opinion Specs facilitates a cleaner testing style and has really wonderful integration with my preferred mocking library, <a href="http://mockito.org/">Mockito</a>. In the end it&#8217;s really just a matter of personal preference.</p>
<h3>The static call</h3>
<p>My first challenge to overcome is the static method call to the Google App Engine&#8217;s UserServiceFactory:</p>
<pre><span style="color:#000000;"><strong>UserServiceFactory</strong></span>.<span style="color:#008000;">getUserService</span></pre>
<p>As it stands, the LoginSnippet object is untestable without including a mocking framework that supports the mocking of static method calls. Whilst Mockito provides simple and elegant mocking, it does not support the mocking of static method calls.</p>
<p>A quick introspection into the UserServiceFactory shows that (as of v1.2.0) the factory method is simply:</p>
<pre><span style="color:#000080;">return new</span> <strong>UserServiceImpl</strong>();</pre>
<p>But it would be a bad idea to replace the current call to the factory with this instantiation because:</p>
<ol>
<li>it may not be backwards compatible as the GAE SDK is updated;</li>
<li>it may not be the same implementation once deployed to the service; and</li>
<li>it simply doesn&#8217;t work (UserServiceImpl is package private).</li>
</ol>
<p>At this stage I&#8217;m forced to modify my class to facilitate my test. The primary constructor is modified to take an injected UserService. (It makes me cringe a bit to do this, but can it be done without using AOP or a different mocking library? Please fill me in on the secret if you know how).</p>
<pre><span style="color:#000000;"> <span style="color:#ff6600;">1:</span> <span style="color:#003366;">class</span> <span style="text-decoration:underline;"><strong>LoginSnippet</strong></span>(userService: <strong>UserService</strong>) {
 <span style="color:#ff6600;">2:</span>     <span style="color:#003366;">def this</span>() = <span style="color:#003366;">this</span> (<strong>UserServiceFactory</strong>.<span style="color:#008000;">getUserService</span>)
 <span style="color:#ff6600;">3:</span>     <span style="color:#003366;">def</span> <strong>render</strong>(request: _root_.javax.servlet.http.<strong>HttpServletRequest</strong>) = {
            ... <em>function continues as per my previous post ...</em>
<span style="color:#ff6600;">14:</span>     }
<span style="color:#ff6600;">15:</span> }</span></pre>
<p>The class definition on line 1 provides a new primary constructor. It now takes a UserService parameter. On line 2 a zero-arg constructor is defined that delegates to the primary constructor. There&#8217;s nothing particular to Scala in this scenario. However, it is worth noting that the execution of <span style="color:#000000;"><strong>UserServiceFactory</strong>.</span><span style="color:#008000;">getUserService</span> now occurs in the constructor. If I needed it to continue to be executed in the render function I could do the following:</p>
<pre><span style="color:#000000;"> <span style="color:#ff6600;">1:</span> <span style="color:#003366;">class</span> <span style="text-decoration:underline;"><strong>LoginSnippet</strong></span>(getUserService: =&gt; <strong>UserService</strong>) {
 <span style="color:#ff6600;">2:</span>     <span style="color:#003366;">def this</span>() = <span style="color:#003366;">this</span> (<strong>{UserServiceFactory</strong>.<span style="color:#008000;">getUserService</span>})
 <span style="color:#ff6600;">3:</span>     <span style="color:#003366;">def</span> <strong>render</strong>(request: _root_.javax.servlet.http.<strong>HttpServletRequest</strong>) = {
 <span style="color:#ff6600;">4:</span>         <span style="color:#003366;">val</span> userService = getUserService</span></pre>
<p>The distinction here is that the constructor now takes a parameter which <em>implies</em> (=&gt;) a UserService. It may be a literal UserService instance (as our test-time mock would be), or it may be a code block that returns a UserService, as can be seen on line 2 (note the added curly braces). If a code block is passed, it will not be executed until invoked on line 4.</p>
<h3>Running Specs with Mockito via Ant</h3>
<p>As is stands, there is currently a small trick to getting Specs running via Ant. It is clearly documented on their site, but I sometimes have a blind spot when it comes to RTFM&#8217;ing. Here it is in a nutshell:</p>
<pre><span style="color:#000000;"><span style="color:#ff6600;">1:</span> <span style="color:#003366;">import</span> org.specs.Specification
<span style="color:#ff6600;">2:</span> <span style="color:#003366;">import</span> org.specs.mock.Mockito
<span style="color:#ff6600;">3:</span> <span style="color:#003366;">import</span> org.specs.runner.JUnit4
<span style="color:#ff6600;">4:</span> <span style="color:#003366;">class</span> <strong>SnippetSpecs</strong> <span style="color:#003366;">extends</span> JUnit4(snippetSpec)
<span style="color:#ff6600;">5:</span> <span style="color:#003366;">object</span> <strong>snippetSpec</strong> <span style="color:#003366;">extends</span> Specification <span style="color:#003366;">with</span> Mockito { ... }</span></pre>
<p>The Specifications must be defined in an object (line 5), but the JUnit Ant task will require a class instance (line 4). The class must be something that JUnit knows how to run and so must extend the Specs JUnit4 runner. Finally, the addition of the Mockito trait (line 5) provides syntactic sugar to sweeten the mocking experience.</p>
<p>In the Ant build.xml the specs are executed with the junit task. The batchtest fileset should include the classes (in my case *Specs) and not the objects (*Spec).</p>
<h3>Testing the sign-in snippet with mocks and XML matchers</h3>
<p>The sign-in snippet should be shown when we don&#8217;t have a currently logged-in user. This forms the basis of my first specification. The task seems simple &#8211; ensure the user is null and assert the correct XHTML is returned.<br />
<!--  .CharacterLiteral {} .Keyword {} .xml {} --></p>
<pre>1:  <span style="color:#ce7b00;">"LoginSnippet with an unknown user"</span> should {
2:      <span style="color:#ce7b00;">"Provide a login prompt"</span> in {
3:          userService.getCurrentUser returns <span style="color:#0000e6;">null</span>
4:          request.getRequestURI returns <span style="color:#ce7b00;">"requestURI"</span>
5:          userService.createLoginURL(<span style="color:#ce7b00;">"requestURI"</span>) returns <span style="color:#ce7b00;">"loginURL"</span>
6:          <span style="color:#0000e6;">val</span> xhtml = snippet render request
7:          xhtml must ==/(<span style="color:#2e92c7;">&lt;</span><span style="color:#2e92c7;">p</span><span style="color:#2e92c7;">&gt;</span>Hello! <span style="color:#2e92c7;">&lt;</span><span style="color:#2e92c7;">a</span> <span style="color:#2e92c7;">href</span>=<span style="color:#ce7b00;">"loginURL"</span><span style="color:#2e92c7;">&gt;</span>Sign in<span style="color:#2e92c7;">&lt;/</span><span style="color:#2e92c7;">a</span><span style="color:#2e92c7;">&gt;</span> just for kicks.<span style="color:#2e92c7;">&lt;/</span><span style="color:#2e92c7;">p</span><span style="color:#2e92c7;">&gt;</span>)
        }
    }</pre>
<p>The specification is described on lines 1-2. The mock expectations are established on lines 3-5 (notice how clean the syntax is, thanks to the Specs&#8217; Mockito trait?). The code under test is executed on line 6. The expectation is asserted on line 7.</p>
<p>The expectation makes use of one of Spec&#8217;s <a href="http://code.google.com/p/specs/wiki/MatchersGuide#Matchers_applicable_to_XML">XML matchers</a>. Matchers are powerful tools for asserting only the aspects of the comparisons that are relevant. In this case, the must ==/ matcher compares the equality of a node sequence whilst ignoring whitespace.</p>
<h3>Testing the sign-out snippet &#8211; splitting hairs over Atoms</h3>
<p>The sign-out snippet seems equally as straight-forward, but there is a catch. My first approach was:</p>
<pre>1:  <span style="color:#ce7b00;">"LoginSnippet with a known user"</span> should {
2:      <span style="color:#ce7b00;">"Provide a logout prompt"</span> in {
3:          <span style="color:#0000e6;">val</span> user = <span style="color:#0000e6;">new</span> User(<span style="color:#ce7b00;">"x"</span>, <span style="color:#ce7b00;">"y"</span>)
4:          userService.getCurrentUser returns user
5:          request.getRequestURI returns <span style="color:#ce7b00;">"requestURI"</span>
6:          userService.createLogoutURL(<span style="color:#ce7b00;">"requestURI"</span>) returns <span style="color:#ce7b00;">"logoutURL"</span>
7:          <span style="color:#0000e6;">val</span> xhtml = snippet render request
8:          xhtml must ==/(<span style="color:#2e92c7;">&lt;</span><span style="color:#2e92c7;">p</span><span style="color:#2e92c7;">&gt;</span>Hello, x! Now you can <span style="color:#2e92c7;">&lt;</span><span style="color:#2e92c7;">a</span> <span style="color:#2e92c7;">href</span>=<span style="color:#ce7b00;">"logoutURL"</span><span style="color:#2e92c7;">&gt;</span>sign out<span style="color:#2e92c7;">&lt;/</span><span style="color:#2e92c7;">a</span><span style="color:#2e92c7;">&gt;</span> again.<span style="color:#2e92c7;">&lt;/</span><span style="color:#2e92c7;">p</span><span style="color:#2e92c7;">&gt;</span>)
        }
    }</pre>
<p>This specification fails! The XML on line 8 seems to be what we are receiving, but the equality matcher failed. After inspecting the returned node sequence closely it seems that the string &#8220;Hello, x! Now you can &#8221; is not a single text element, but a chain of text/atom/text. The <a href="http://www.scala-lang.org/docu/files/api/scala/xml/Atom.html">Atom</a> (the parent class of Text) corresponds to the inlined user name (&#8220;x&#8221;) and, I assume, indicates that the inlined characters may not be valid XML text, but instead PCDATA or Unparsed.</p>
<p>To make the specification pass, line 8 needed to be modified to:</p>
<pre>8:          xhtml must ==/(<span style="color:#2e92c7;">&lt;</span><span style="color:#2e92c7;">p</span><span style="color:#2e92c7;">&gt;</span>Hello, {<span style="color:#ce7b00;">"x"</span>}! Now you can <span style="color:#2e92c7;">&lt;</span><span style="color:#2e92c7;">a</span> <span style="color:#2e92c7;">href</span>=<span style="color:#ce7b00;">"logoutURL"</span><span style="color:#2e92c7;">&gt;</span>sign out<span style="color:#2e92c7;">&lt;/</span><span style="color:#2e92c7;">a</span><span style="color:#2e92c7;">&gt;</span> again.<span style="color:#2e92c7;">&lt;/</span><span style="color:#2e92c7;">p</span><span style="color:#2e92c7;">&gt;</span>)</pre>
<p>Now that I have the behaviour-driven testing essentials under my belt, it&#8217;s all go to proceed on adding some features to my application.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=65&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2009/04/12/testing-the-login-snippet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
		<item>
		<title>First steps with Scala on Google App Engine</title>
		<link>http://mawson.wordpress.com/2009/04/10/first-steps-with-scala-on-google-app-engine/</link>
		<comments>http://mawson.wordpress.com/2009/04/10/first-steps-with-scala-on-google-app-engine/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 09:32:06 +0000</pubDate>
		<dc:creator>Jem</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[LiftWeb]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[lift]]></category>

		<guid isPermaLink="false">http://mawson.wordpress.com/?p=52</guid>
		<description><![CDATA[Google App Engine recently added support for Java. As a beautiful side-effect of this, Scala is supported. Unfortunately the delicious Scala-based web framework Lift does not work there, due to sandbox constraints in GAE around thread creation and JDBC access. (Though there is hope that David Pollak will get core Lift working with GAE as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=52&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://code.google.com/appengine/">Google App Engine</a> recently added <a href="http://googleappengine.blogspot.com/2009/04/seriously-this-time-new-language-on-app.html">support for Java</a>. As a beautiful side-effect of this, <a href="http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine">Scala is supported</a>. Unfortunately the delicious Scala-based web framework <a href="http://liftweb.net/">Lift</a> does not work there, due to sandbox constraints in GAE around thread creation and JDBC access. (Though there is hope that David Pollak will get core Lift working with GAE as early as mid April<a href="http://www.nabble.com/Re%3A--scala--Google-App-Engine-for-Scala!-p22951277.html">*</a>).</p>
<p>I&#8217;ve just uploaded a hello world app that is written with a JSP delegating to Scala. (It&#8217;s not worth clicking through to, but it is <a href="http://scala-chess.appspot.com/">here</a> if you need proof). Here is what I needed to do, once I had signed up and downloaded the SDK.</p>
<p>First you need to create the right project structure. You can get it automagically if you are using the Eclipse plugin, but I find that particular IDE to be a choking hazard. Here&#8217;s the structure I created manually.</p>
<ul>
<li><em>project_root</em>
<ul>
<li>src</li>
<li>web
<ul>
<li>WEB-INF
<ul>
<li>classes</li>
<li>lib</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>The one-and-only page is the JSP <em>war/index.jsp</em>. It delegates to the Scala class.</p>
<div style="border:1px solid #E4E4E4;padding:15px;">
<pre><code><span style="color:#339966;">&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
&lt;%@ page import="au.com.loftinspace.scalachess.LoginSnippet" %&gt;</span>
<span style="color:#000080;">&lt;html&gt;</span><span style="color:#000080;">
  &lt;body&gt;
    &lt;h1&gt;</span>Just a test<span style="color:#000080;">&lt;/h1&gt;</span>
    <span style="color:#000080;">&lt;%=</span> <span style="color:#ff6600;">LoginSnippet.render(request)</span> <span style="color:#000080;">%&gt;</span>
  <span style="color:#000080;">&lt;/body&gt;
&lt;/html&gt;</span></code></pre>
</div>
<p>The custom Scala object providing the XHTML snippet to display is defined in LoginSnippet.scala</p>
<div style="border:1px solid #E4E4E4;padding:15px;">
<pre><code><span style="color:#000080;">package</span> <span style="color:#000000;">au.com.loftinspace.scalachess</span>

<span style="color:#000080;">object</span><span style="color:#000000;"> <strong>LoginSnippet</strong> {</span>
    <span style="color:#000080;">def</span> <span style="color:#000000;"><strong>render</strong>(request: _root_.javax.servlet.http.HttpServletRequest) = {</span>
        <span style="color:#000080;">import</span><span style="color:#000000;"> _root_.com.google.appengine.api.users._</span>
        <span style="color:#000080;">val</span> <span style="color:#000000;">userService = <strong>UserServiceFactory</strong>.</span><span style="color:#008000;">getUserService</span>
        <span style="color:#000080;">val</span> <span style="color:#000000;">user = userService.</span><span style="color:#008000;">getCurrentUser</span>

        <span style="color:#000080;">if</span> <span style="color:#000000;">(user ==</span> <span style="color:#000080;">null</span><span style="color:#000000;">) {</span>
            <span style="color:#33cccc;">&lt;p&gt;</span><span style="color:#000000;">Hello!</span> <span style="color:#33cccc;">&lt;a href</span><span style="color:#000000;">={userService.</span><span style="color:#008000;">createLoginURL
                </span><span style="color:#000000;">(request.</span><span style="color:#008000;">getRequestURI</span><span style="color:#000000;">)}</span><span style="color:#33cccc;">&gt;</span><span style="color:#000000;">Sign in</span><span style="color:#33cccc;">&lt;/a&gt;</span>
                <span style="color:#000000;">just for kicks.</span><span style="color:#33cccc;">&lt;/p&gt;</span>
        <span style="color:#000000;">}</span> <span style="color:#000080;">else</span> <span style="color:#000000;">{</span>
            <span style="color:#33cccc;">&lt;p&gt;</span><span style="color:#000000;">Hello, {user.</span><span style="color:#008000;">getNickname</span><span style="color:#000000;">}! Now you can</span>
                <span style="color:#33cccc;">&lt;a href=</span><span style="color:#000000;">{userService.</span><span style="color:#008000;">createLogoutURL</span><span style="color:#000000;">(
                request.</span><span style="color:#008000;">getRequestURI</span><span style="color:#000000;">)}</span><span style="color:#33cccc;">&gt;</span><span style="color:#000000;">sign out</span><span style="color:#33cccc;">&lt;/a&gt;</span> <span style="color:#000000;">again.</span><span style="color:#33cccc;">&lt;/p&gt;</span>
        <span style="color:#000000;">}
    }
}</span></code></pre>
</div>
<p>Scala classes need to be compiled to <em>web/WEB-INF/classes</em> (just as Java classes would). When compiling the class I required the following on the classpath:</p>
<ul>
<li><em>appengine-java-sdk</em>/lib/shared/geronimo-servlet_2.5_spec-1.2.jar (for HttpServletRequest); and</li>
<li><em>appengine-java-sdk</em>/lib/user/appengine-api-1.0-sdk-1.2.0.jar (for the User functionality)</li>
</ul>
<p>Some jars need to be deployed with your application. This simply means placing them in <em>web/WEB-INF/lib</em>. The jars I required were:</p>
<ul>
<li>scala-library.jar (for the scala -&gt; java bridging objects you get when scala is compiled, and several classes from scala.xml._ which I have used implicitly by defining the inline XML in the render function).</li>
<li>appengine-api-1.0-sdk-1.2.0.jar (which surprises me a little, as I thought GAE could provide this itself)</li>
</ul>
<p>This is a reworked version of login as seen in the SDK&#8217;s demo application GuestBook. It is worth noting that the User functionality allows any username when running under the SDK&#8217;s development server, but integrates with Google account authentication once published to GAE.</p>
<p><strong>Update:</strong> David Pollak &#8211; In case you missed it, Lift *does* run on the Google App Engine <a href="http://lift-example.appspot.com/index">http://lift-example.appspot.com/index</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mawson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mawson.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mawson.wordpress.com&#038;blog=1123238&#038;post=52&#038;subd=mawson&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mawson.wordpress.com/2009/04/10/first-steps-with-scala-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ad29aa440f6e173b88157c35c5d4db33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jem</media:title>
		</media:content>
	</item>
	</channel>
</rss>
