<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PyRuby blog &#187; scala</title>
	<atom:link href="http://www.pyruby.com/category/geek/scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pyruby.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 12 Dec 2011 11:03:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Scala JSON Generator</title>
		<link>http://www.pyruby.com/2010/04/29/scala-json-generator/</link>
		<comments>http://www.pyruby.com/2010/04/29/scala-json-generator/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 05:56:08 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=72</guid>
		<description><![CDATA[<p>I am working with Scala more and more at the moment.  I find it a really powerful and fun language to work in.  One of the recent tasks has been to translate various tab delimited data files into a common JSON format.  In java land, I&#8217;ve used Jackson to great effect, but [...]]]></description>
			<content:encoded><![CDATA[<p>I am working with <a href="http://www.scala-lang.org/">Scala</a> more and more at the moment.  I find it a really powerful and fun language to work in.  One of the recent tasks has been to translate various tab delimited data files into a common JSON format.  In java land, I&#8217;ve used <a href="http://jackson.codehaus.org">Jackson</a> to great effect, but it really doesn&#8217;t feel very Scala.  My colleague and I were busy following the Jackson route and had a working implementation, but it just didn&#8217;t feel clean, simple and Scala idiomatic.  That&#8217;s when we decided to define how we thought the api should work.</p>
<p>One of the great things about using Scala, is it&#8217;s a fantastic language for creating <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSLs</a>.  When I really don&#8217;t like the way the code that solves a specific problem looks, I like to write the pseudo code that feels right, and then figure out how to make that work.  With Scala, I have had a great deal of success in this approach.  We started off defining a JSON generator DSL that looked like this:-</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">def mapToJson(myMap: Map[String, String]) = {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; val json = jsonObject {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; field(&quot;cheese&quot;, myMap.get(&quot;name&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; jsonObject(&quot;Score&quot;) {
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; field(&quot;aroma&quot;, myMap.get(&quot;smell&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; field(&quot;flavor&quot;, myMap.get(&quot;taste&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; field(&quot;texture&quot;, myMap.get(&quot;squidginess&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; jsonArray(&quot;servedOn&quot;) {
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; jsonObject {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; field(&quot;cracker&quot;, myMap.get(&quot;crackerType&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; field(&quot;maker&quot;, myMap.get(&quot;crackerMaker&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; jsonArray(&quot;sampledOn&quot;) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; value(myMap.get(&quot;firstTried&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; value(myMap.get(&quot;secondTried&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; value(myMap.get(&quot;thirdTried&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li2">
<div class="de2">}</div>
</li>
</ol>
</div>
<p>There was another case for jsonArray, which doesn&#8217;t involve having a field name, i.e. jsonArray { &#8230; }.  Whilst attempting to find a way to implement the DSL that would satisfy this, we had to make a small compromise.  The call jsonObject {&#8230;} and jsonObject(&#8220;fieldName&#8221;) {&#8230;} caused problems because the signatures of the DSL methods were indistinguishable when using them.  The compromise we struck on was jsonObject() {&#8230;} and jsonObject(&#8220;fieldName&#8221;) {&#8230;}, i.e. just adding the empty parenthesis.  This then is the resulting syntax, and the implementation can be found <a href="http://github.com/jtownley/Scala-Json-Generator">here</a>.  </p>
<p>This is a first cut, but as this library was introduced to solve a problem in our production app.  It will be tweaked and maintained so any bugs or extra features will quickly get incorporated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2010/04/29/scala-json-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Writing Scala code in IntelliJ IDEA</title>
		<link>http://www.pyruby.com/2009/10/15/writing-scala-code-in-intellij-idea/</link>
		<comments>http://www.pyruby.com/2009/10/15/writing-scala-code-in-intellij-idea/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:00:47 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=39</guid>
		<description><![CDATA[<p>Just read that IntelliJ IDEA 9 will be split into a Community Edition, and an Ultimate Edition.  The Community Edition will be open sourced, and allows the Scala plugin.  I&#8217;ve been writing Scala code for a few months now, and using IDEA in the office, and TextMate at home.  I&#8217;m really hoping [...]]]></description>
			<content:encoded><![CDATA[<p>Just read that <a href="http://blogs.jetbrains.com/idea/2009/10/intellij-idea-open-sourced/">IntelliJ IDEA 9</a> will be split into a Community Edition, and an Ultimate Edition.  The Community Edition will be open sourced, and allows the <a href="http://www.scala-lang.org">Scala</a> plugin.  I&#8217;ve been writing Scala code for a few months now, and using IDEA in the office, and <a href="http://macromates.com/">TextMate</a> at home.  I&#8217;m really hoping that I&#8217;ll be able to use the open sourced version at home so I don&#8217;t have to context switch so much.  I&#8217;ve tried the Scala plugin for NetBeans, but it is so far off ready, that I prefer using TextMate.  I know the scala plugin for IDEA 8.1 works really well, but it doesn&#8217;t work in the IDEA 9.0 early access release yet.  I hope this gets fixed soon so I can play with scala at home more.</p>
<p>NOTE:  I don&#8217;t recommend using maven with Scala on the Mac, because it just doesn&#8217;t play nicely.  Don&#8217;t know why, but it&#8217;s broken to the point that I no longer even try to use Maven to build my scala code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/10/15/writing-scala-code-in-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

