<?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"
	>

<channel>
	<title>aaron.harnly.net &#187; lang</title>
	<atom:link href="http://harnly.net/category/blog/geek/lang/feed/" rel="self" type="application/rss+xml" />
	<link>http://harnly.net</link>
	<description>Sì, abbiamo un'anima. Ma è fatta di tanti piccoli robot.</description>
	<pubDate>Tue, 21 Oct 2008 03:40:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<item>
		<title>Lazy vals with implicit parameters</title>
		<link>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/</link>
		<comments>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 15:04:54 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/?p=176</guid>
		<description><![CDATA[Lazy vals were an excellent addition to Scala 2.6.0. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached. 

Unfortunately, this doesn&#8217;t play so well with another wonderful Scala feature &#8212; implicit parameters. It&#8217;s often the case that you&#8217;ll want to defer resolution of an [...]]]></description>
			<content:encoded><![CDATA[<p>Lazy vals were an excellent addition to <a href="http://www.scala-lang.org/docu/changelog.html#v2.6.0">Scala 2.6.0</a>. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached. </p>

<p>Unfortunately, this doesn&#8217;t play so well with another wonderful Scala feature &mdash; <a href="http://www.scala-lang.org/intro/implicit.html">implicit parameters</a>. It&#8217;s often the case that you&#8217;ll want to defer resolution of an implicit until a method call, rather than in the scope of object creation. But lazy values cannot take any parameters, implicit or otherwise &mdash; so it seems you&#8217;re stuck.</p>

<p>Memoized to the rescue! This is a simple helper class that takes care of the caching of a result. Where you might have had the following method with an implicit parameter:</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">def</span> foo<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">implicit</span> bar<span style="color: #000080;">:</span> Bar<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> ResultType <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> ... <span style="color: #F78811;">&#125;</span></pre></div></div>


<p>you instead write the following:</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">var</span> <span style="color: #000080;">_</span>foo <span style="color: #000080;">=</span> Memoized<span style="color: #F78811;">&#91;</span>ResultType<span style="color: #F78811;">&#93;</span>
<span style="color: #0000ff; font-weight: bold;">def</span> foo<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">implicit</span> bar<span style="color: #000080;">:</span> Bar<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #000080;">_</span>foo or <span style="color: #F78811;">&#123;</span> ... <span style="color: #F78811;">&#125;</span></pre></div></div>


<p>(complete source below the fold)
<span id="more-176"></span></p>

<p>That&#8217;s it; nothing fancy. This is not a true memoization solution for a function that takes a parameter &mdash; check out <a href="http://projects.workingmouse.com/public/scalaz/trunk/src/main/scalaz/memo/">the memo package</a> in <a href="http://wiki.workingmouse.com/index.php/Scalaz">Scalaz</a> for that. But I&#8217;ve found it handy, and you might too.</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">class</span> Memoized<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
	<span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">var</span> value<span style="color: #000080;">:</span> Option<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> None
	<span style="color: #0000ff; font-weight: bold;">def</span> isEmpty <span style="color: #000080;">=</span> value.<span style="color: #000000;">isEmpty</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> isDefined <span style="color: #000080;">=</span> <span style="color: #000080;">!</span> isEmpty
	<span style="color: #0000ff; font-weight: bold;">def</span> get<span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> value.<span style="color: #000000;">get</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> set<span style="color: #F78811;">&#40;</span>newValue<span style="color: #000080;">:</span> T<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> value <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#125;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> getOrSet<span style="color: #F78811;">&#40;</span> newValue<span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> T<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>isDefined<span style="color: #F78811;">&#41;</span> get <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #F78811;">&#123;</span>
		set<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span>
		get
	<span style="color: #F78811;">&#125;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> or<span style="color: #F78811;">&#40;</span> newValue<span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> T<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> getOrSet<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span>
	<span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> toString <span style="color: #000080;">=</span> value.<span style="color: #000000;">toString</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> Memoized <span style="color: #F78811;">&#123;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> apply<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Memoized<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Somebody oughta&#8230;</title>
		<link>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 20:57:57 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[markdown]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/</guid>
		<description><![CDATA[&#8230;write a JavaDoc Doclet so I can use Markdown instead of nasty old HTML in source code comments. How nice would that be?

While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.
]]></description>
			<content:encoded><![CDATA[<p>&#8230;write a <a href="http://java.sun.com/j2se/javadoc/">JavaDoc</a> <a href="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/overview.html">Doclet</a> so I can use <a href="http://daringfireball.net/projects/markdown/">Markdown</a> instead of nasty old HTML in source code comments. How nice would that be?</p>

<p>While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Somebody oughta&#8230;</title>
		<link>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta-2/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta-2/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 20:57:57 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[markdown]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/autobiography/somebody-oughta-2/</guid>
		<description><![CDATA[&#8230;write a JavaDoc Doclet so I can use Markdown instead of nasty old HTML in source code comments. How nice would that be?

While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.
]]></description>
			<content:encoded><![CDATA[<p>&#8230;write a <a href="http://java.sun.com/j2se/javadoc/">JavaDoc</a> <a href="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/overview.html">Doclet</a> so I can use <a href="http://daringfireball.net/projects/markdown/">Markdown</a> instead of nasty old HTML in source code comments. How nice would that be?</p>

<p>While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>TextMate bundle for Scala</title>
		<link>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 18:52:11 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/textmate-bundle-for-scala/</guid>
		<description><![CDATA[I&#8217;ve put together a stub of a TextMate bundle for Scala. 

At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I&#8217;d like to keep improving it, and would welcome suggestions and modifications.

I&#8217;ll be setting up anonymous SVN access one of these days (yeah, right), [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put together a stub of a <a href="http://macromates.com/textmate/manual/bundles">TextMate bundle</a> for <a href="http://www.scala-lang.org">Scala</a>. </p>

<p>At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I&#8217;d like to keep improving it, and would welcome suggestions and modifications.</p>

<p>I&#8217;ll be setting up anonymous SVN access one of these days (yeah, right), but for the moment, you can download the bundle directly: </p>

<p><a href="/projects/scala-textmate-bundle/downloads/ScalaAWH.tmbundle.zip"><img src="/projects/images/filetypes/128/tmbundle.png">
ScalaAWH.tmbundle.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NLTK&#8217;s &#8220;ing words&#8221;: variations</title>
		<link>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations/#comments</comments>
		<pubDate>Sun, 22 Apr 2007 13:36:23 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/ruby/nltks-ing-words-variations/</guid>
		<description><![CDATA[NLTK, the &#8220;natural language toolkit&#8221; for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a little appendix describing the advantages of Python for implementing and (especially) teaching NLP.

The authors show a simple sample program to find and list words [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nltk.sourceforge.net">NLTK, the &#8220;natural language toolkit&#8221;</a> for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a <a href="http://nltk.sourceforge.net/lite/doc/en/nlp-python.html">little appendix describing the advantages of Python</a> for implementing and (especially) teaching NLP.</p>

<p>The authors show a simple sample program to find and list words ending in &#8220;ing&#8221; from the standard input:</p>

<p><code>import sys
for line in sys.stdin.readlines():
    for word in line.split():
        if word.endswith('ing'):
            print word</code></p>

<p>and contrast this elegant Python implementation with a variety of monstrosities in other languages. I won&#8217;t disagree that the Python is nice, but it seemed like a good little exercise to see whether I can&#8217;t produce something almost as good in my languages de jour.</p>

<p>To wit, a Ruby version:
<code>for line in ARGF 
  for word in line.split
    if word.match(/ing$/) then
      puts word<br />
    end
  end
end
</code></p>

<p>which is almost identical to the Python version, though showing Ruby&#8217;s not-exactly-pretty fascination with the &#8216;end&#8217; keyword.</p>

<p>And a Scala version using for-comprehensions. Note to Scala creators: It&#8217;s really frustrating having the various ways of executing Scala &#8212; as a script, as an object, etc. &#8212; all disagree slightly on how the outermost wrapper of a procedure should be formatted. </p>

<p><code>import scala.io._
object IngWords extends Application {
   for (
      val line &lt;- Source.fromInputStream(System.in).getLines;
      val word &lt;- line.split(" ");
      word.endsWith("ing")
   ) 
  Console.println(word)<br />
}</code></p>

<p>(Aside: I need a decent syntax highlighting package for WP, it seems.)</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NLTK&#8217;s &#8220;ing words&#8221;: variations</title>
		<link>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations-2/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations-2/#comments</comments>
		<pubDate>Sun, 22 Apr 2007 13:36:23 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/autobiography/nltks-ing-words-variations-2/</guid>
		<description><![CDATA[NLTK, the &#8220;natural language toolkit&#8221; for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a little appendix describing the advantages of Python for implementing and (especially) teaching NLP.

The authors show a simple sample program to find and list words [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nltk.sourceforge.net">NLTK, the &#8220;natural language toolkit&#8221;</a> for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a <a href="http://nltk.sourceforge.net/lite/doc/en/nlp-python.html">little appendix describing the advantages of Python</a> for implementing and (especially) teaching NLP.</p>

<p>The authors show a simple sample program to find and list words ending in &#8220;ing&#8221; from the standard input:</p>

<p><code>import sys
for line in sys.stdin.readlines():
    for word in line.split():
        if word.endswith('ing'):
            print word</code></p>

<p>and contrast this elegant Python implementation with a variety of monstrosities in other languages. I won&#8217;t disagree that the Python is nice, but it seemed like a good little exercise to see whether I can&#8217;t produce something almost as good in my languages de jour.</p>

<p>To wit, a Ruby version:
<code>for line in ARGF 
  for word in line.split
    if word.match(/ing$/) then
      puts word<br />
    end
  end
end
</code></p>

<p>which is almost identical to the Python version, though showing Ruby&#8217;s not-exactly-pretty fascination with the &#8216;end&#8217; keyword.</p>

<p>And a Scala version using for-comprehensions. Note to Scala creators: It&#8217;s really frustrating having the various ways of executing Scala &#8212; as a script, as an object, etc. &#8212; all disagree slightly on how the outermost wrapper of a procedure should be formatted. </p>

<p><code>import scala.io._
object IngWords extends Application {
   for (
      val line &lt;- Source.fromInputStream(System.in).getLines;
      val word &lt;- line.split(" ");
      word.endsWith("ing")
   ) 
  Console.println(word)<br />
}</code></p>

<p>(Aside: I need a decent syntax highlighting package for WP, it seems.)</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>each_line do &#124;line&#124; in Scala</title>
		<link>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala/#comments</comments>
		<pubDate>Wed, 28 Mar 2007 04:32:16 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/scala/each_line-do-line-in-scala/</guid>
		<description><![CDATA[I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. 

Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:

   def eachline(stream : InputStream)(f : String => Unit) {
      val [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. </p>

<p>Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:</p>

<p><code>   def eachline(stream : InputStream)(f : String => Unit) {
      val buf = new BufferedReader( new InputStreamReader( stream ) )
      var line = buf.readLine
      while (line != null) {
         f(line)
         line = buf.readLine
      }
   }
</code></p>

<p>I use this with a block as so:
<code>      eachline(System.in) { line =>
         Console.println(line)
      }
</code></p>

<p>Not bad, but it could be better, I think. Can I tickle this to be a method on streams, instead of a funny little function sitting on its own?</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala/feed/</wfw:commentRss>
		</item>
		<item>
		<title>each_line do &#124;line&#124; in Scala</title>
		<link>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala-2/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala-2/#comments</comments>
		<pubDate>Wed, 28 Mar 2007 04:32:16 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/autobiography/each_line-do-line-in-scala-2/</guid>
		<description><![CDATA[I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. 

Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:

   def eachline(stream : InputStream)(f : String => Unit) {
      val [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. </p>

<p>Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:</p>

<p><code>   def eachline(stream : InputStream)(f : String => Unit) {
      val buf = new BufferedReader( new InputStreamReader( stream ) )
      var line = buf.readLine
      while (line != null) {
         f(line)
         line = buf.readLine
      }
   }
</code></p>

<p>I use this with a block as so:
<code>      eachline(System.in) { line =>
         Console.println(line)
      }
</code></p>

<p>Not bad, but it could be better, I think. Can I tickle this to be a method on streams, instead of a funny little function sitting on its own?</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Scala is my new Ruby</title>
		<link>http://harnly.net/2007/blog/geek/lang/ruby/scala-is-my-new-ruby/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/ruby/scala-is-my-new-ruby/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 00:36:40 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/ruby/scala-is-my-new-ruby/</guid>
		<description><![CDATA[Scala is my new Ruby, i.e. the language I love to tinker in. Rather more practical, too, as the fact that Ruby is dog-slow has gotten in the way of my work more than once recently.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.scala-lang.org/">Scala</a> is my new <a href="http://www.ruby-lang.org/">Ruby</a>, i.e. the language I love to tinker in. Rather more practical, too, as the fact that <a href="http://shootout.alioth.debian.org/debian/benchmark.php?test=all&amp;lang=ruby&amp;lang2=java">Ruby is dog-slow</a> has gotten in the way of my work more than once recently.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/ruby/scala-is-my-new-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>From DTD to Rails Migrations</title>
		<link>http://harnly.net/2007/blog/geek/lang/ruby/from-dtd-to-rails-migrations/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/ruby/from-dtd-to-rails-migrations/#comments</comments>
		<pubDate>Wed, 07 Mar 2007 21:29:06 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/ruby/from-dtd-to-rails-migrations/</guid>
		<description><![CDATA[In the category of tools that I want, but better not make right now, lest it turn into a &#8220;paroxysm of generalization&#8221;:

I have a DTD, describing a bunch of entities, their relationships, and their attributes. I&#8217;m going to push data from a set of XML files (adhering to said DTD) into a Ruby-on-Rails savvy database. [...]]]></description>
			<content:encoded><![CDATA[<p>In the category of tools that I want, but better not make right now, lest it turn into a &#8220;paroxysm of generalization&#8221;:</p>

<p>I have a DTD, describing a bunch of entities, their relationships, and their attributes. I&#8217;m going to push data from a set of XML files (adhering to said DTD) into a Ruby-on-Rails savvy database. Wouldn&#8217;t be nice to have a simple tool that, in the most general way possible, would, given that DTD:</p>

<ol>
<li><p>Issue a series of &#8217;script/general model Foo&#8217; commands for the various entities.</p></li>
<li><p>Populate the Rails migration files appropriately, to manage the creation of the database tables for these entities. That would include inserting :foo_id columns for has-many and has-and-belongs-to-many relationships (though differentiating between the two might require some human supervision), and exploiting the wonderful Red Hill Foreign Key Migrations to create appropriate FK constraints. </p></li>
<li><p>In addition / as an alternative to using the Red Hill plugin, insert the appropriate has_many / habtm declarations in the model files.</p></li>
<li><p>And finally, make a script that can read a set of such XML files and fill the database appropriately.</p></li>
</ol>

<p>Well, sounds nice to me, anyway. Put it on the someday-maybe list.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/ruby/from-dtd-to-rails-migrations/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 3.444 seconds -->
