<?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>Holy Grails - the blog</title>
	<atom:link href="http://blog.holygrails.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.holygrails.net</link>
	<description>Groovy And Grails Goodness</description>
	<pubDate>Sat, 28 Jun 2008 18:03:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Breaking out of closures</title>
		<link>http://blog.holygrails.net/groovy/breaking-out-of-closures/</link>
		<comments>http://blog.holygrails.net/groovy/breaking-out-of-closures/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 17:58:47 +0000</pubDate>
		<dc:creator>npiv</dc:creator>
		
		<category><![CDATA[gotcha]]></category>

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

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

		<guid isPermaLink="false">http://blog.holygrails.net/?p=7</guid>
		<description><![CDATA[coming from java I&#8217;m used to using break &#38; continue to manipulate loops. Groovy doesn&#8217;t allow these keywords, so iterating with closures presented a problem.
Consider a piece of code like:
List people = // instantiate some Person &#8217;s (idiots at the back)

// print the useful people
for (Person person : people) {
    if (person.isNuisance()) [...]]]></description>
			<content:encoded><![CDATA[<p>coming from java I&#8217;m used to using <strong>break &amp; continue </strong>to manipulate loops. Groovy doesn&#8217;t allow these keywords, so iterating with closures presented a problem.</p>
<p>Consider a piece of code like:</p>
<pre class="prettyprint">List<Person> people = // instantiate some Person &#8217;s (idiots at the back)

// print the useful people
for (Person person : people) {
    if (person.isNuisance()) {
        break;
    }
    System.out.println(&#8221;name : &#8221; + person.getName());
}</pre>
<p>To achieve the same effect in groovy, the common trick is to use .find {} rather than .each{}</p>
<p>find loops over all the items in the list just like each, except it breaks out and returns the current object when a true condition is returned from the closure. So there is no reason why you can&#8217;t add logic to find, and use it in this manner</p>
<pre class="prettyprint">class Person { String name; boolean nuisance}

def people = [new Person(name:"person1",nuisance:false),
              new Person(name:"person2",nuisance:false),
	      new Person(name:"person3",nuisance:true),
	      new Person(name:"person4",nuisance:true)]

people.find() {
	if (it.nuisance) return true // break out
	println it.name
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.holygrails.net/groovy/breaking-out-of-closures/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Groovy Builders Primer</title>
		<link>http://blog.holygrails.net/groovy/groovy-builders-primer/</link>
		<comments>http://blog.holygrails.net/groovy/groovy-builders-primer/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 19:09:25 +0000</pubDate>
		<dc:creator>npiv</dc:creator>
		
		<category><![CDATA[gotcha]]></category>

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

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

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

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

		<guid isPermaLink="false">http://blog.holygrails.net/?p=6</guid>
		<description><![CDATA[Groovy lends itself to be extremely useful as a builder for all sorts of data structures. This article intends to investigate why that is. What exactly are builders? And why is groovy so good at it.
To answer these questions, 2 important concepts need to be addressed first

DSL - Domain Specific Languages
The Builder Pattern

Domain Specific Languages
He [...]]]></description>
			<content:encoded><![CDATA[<p>Groovy lends itself to be extremely useful as a builder for all sorts of data structures. This article intends to investigate why that is. What exactly are builders? And why is groovy so good at it.</p>
<p>To answer these questions, 2 important concepts need to be addressed first</p>
<ol>
<li>DSL - Domain Specific Languages</li>
<li>The Builder Pattern</li>
</ol>
<h4>Domain Specific Languages</h4>
<blockquote><p><span class="body">He that is good with a hammer tends to think everything is a nail &#8212; </span><span class="bodybold"> Abraham Maslow </span></p></blockquote>
<p>Advocates of ruby, and more recently groovy have traditionally embraced the &#8220;best tool for the job&#8221; attitude. The <em>Pragmatic Programmer</em> (a must have in any developers bookshelf ) suggests learning a new language every year. For some this might be taking it a step too far, but it definitely fits the former argument.</p>
<p>Computer science knows all too many <em>one trick ponies</em> who get stuck inside that one language of their choosing, and spend the majority of their free time insecurely and childishly flaming the new programming language on the block. The evident truth is that one shoe never first all, and a little flexibility in mindset goes a long way towards solving a problem. Which brings us to the concept of a DSL</p>
<blockquote><p>The basic idea of a domain specific language (DSL) is a computer 		language that&#8217;s targeted to a particular kind of problem, rather 		than a general purpose language that&#8217;s aimed at any kind of 		software problem. Domain specific languages have been talked 		about, and used for almost as long as computing has been done. &#8211;<a title="Martin fowler DSL" href="http://martinfowler.com/bliki/DomainSpecificLanguage.html" target="_blank"> Martin Fowler</a></p></blockquote>
<p>XML is the current reigning king of this field. Unfortunately one may add . From a java background you&#8217;ll be familiar with XML as a DSL for:</p>
<ul>
<li>Spring Configuration</li>
<li>Ant build files</li>
<li>log4j</li>
<li>hibernate mappings (pre annotations)</li>
<li>container configs (Tomcat / JBOSS / &#8230;)</li>
<li>web.xml</li>
</ul>
<p>With all the advantages that XML files do carry. Such as allowing a strict definition through XSL/DTD as well as being able to define any datatype you wish, there is one major pitfall. XML is not a programming language and there is no concept of even a simple loop, which is particularly limiting in something like an ant build file.</p>
<p>Groovy suits itself perfectly as a DSL, because of its loose syntax allowing all sorts of creative possibilities. Closures, easy map definition and the metaclass being key.</p>
<p>The grails framework is a perfect example. GORM - the DSL for hibernate code allows you to define domain classes as follows.</p>
<pre class="prettyprint">  class Author {
	String email
	String username
	String password

	static hasMany = [books:Book]

	static constraints = {
           email(email:true, blank:false, unique:true)
           username(size:4..15, blank:false,unique:true)
           password(size:4..25, blank:false)
       }
   }</pre>
<p>The code is readable, and easily understandable, by people unfamiliar with hibernate or groovy. GORM has in essence defined a DSL (leveraging groovy) to define the model, and the relationships which need to be mapped to the database.</p>
<p>Grails Controllers also utilize groovy in a similar way to provide a DSL for spring web-mvc.</p>
<h4>The Builder Pattern</h4>
<p>The Builder Pattern aims to seperate the creation of complex objects, <em>the product</em>, from its representation.</p>
<p>In a simple example:</p>
<p>If we define the creation steps of compiling our project, generating a war, deploying the war to the server, reloading tomcat in our own custom builder syntax &#8220;GroovyBuilder&#8221;. We could then still freely choose the actual representation. Do we generate an ANT build.xml from it. Or a linux shell script, even a dos batch file? &#8220;GroovyBuilder&#8221; is a generic syntax for building our choice of implementation of production steps.</p>
<p>Looking back at the example above from the GORM domain class Author, we could now also say that GORM is a builder for hibernate mappings. GORM seperates the creation of the model and its relationships from the represenation (the hibernate mapping).</p>
<h4>GANT - Groovy Ant</h4>
<p>GANT is a good example to put all of this together.</p>
<p>Below is a simple ant config:</p>
<pre>&lt;target name="compile"&gt;
   &lt;mkdir dir="target/classes" /&gt;
   &lt;javac srcdir="src" destdir="target/classes" /&gt;
&lt;/target&gt;</pre>
<p>The GANT counterpart</p>
<pre class="prettyprint">target(compile:"compiles source code"){
   Ant.mkdir(dir:"target/classes")
   Ant.javac(srcdir:"src", destdir:"target/classes")
}</pre>
<p>At first site, this might not seem like all too much of an improvement. But the GANT code is pure groovy. Meaning all the conditional logic, and variable declaration is available to the developer. For larger build files this is a godsend.</p>
<p>There are many other, builders out there, which i&#8217;d like to expand upon, soon.</p>
<p>Critics and comments welcome <img src='http://blog.holygrails.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.holygrails.net/groovy/groovy-builders-primer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>holygrails.net goes live</title>
		<link>http://blog.holygrails.net/holygrails/holygrailsnet-goes-live/</link>
		<comments>http://blog.holygrails.net/holygrails/holygrailsnet-goes-live/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 00:11:08 +0000</pubDate>
		<dc:creator>npiv</dc:creator>
		
		<category><![CDATA[holygrails]]></category>

		<guid isPermaLink="false">http://blog.holygrails.net/?p=4</guid>
		<description><![CDATA[We launched the first version of www.holygrails.net
The site is entirely written in grails, and we intend to update and expand it actively in the coming months. Currently we&#8217;ve launched a digg like / dzone voting system based on groovy and grails posts.
One of the great things about the grails community is that it is still [...]]]></description>
			<content:encoded><![CDATA[<p>We launched the first version of <a href="http://www.holygrails.net" target="_blank">www.holygrails.net</a></p>
<p>The site is entirely written in grails, and we intend to update and expand it actively in the coming months. Currently we&#8217;ve launched a digg like / dzone voting system based on groovy and grails posts.</p>
<p>One of the great things about the grails community is that it is still young, and somewhat limited in numbers. Although we hope to see this change, the community is vibrant, and more importantly friendly.</p>
<p>Our mission is to empower the community to filter through the active teachings and blogrolls posted each day, and naturally evolve the better articles to the top. <strong>Without</strong> the negative ,troll activities some of the larger, less focused communities seem to acquire.</p>
<p>Some of the things we are currently working on / would like to see:</p>
<ul>
<li>Plugin rating system - a repository off all plugins, with ratings and comments by the community</li>
<li>Useful RSS feeds - With a more active community, we would hope to provide custom feeds, with a set minimum votes</li>
</ul>
<p>You can see our current site at</p>
<p><a href="http://www.holygrails.net" target="_blank">http://www.holygrails.net</a></p>
<p>are these good ideas - bad? We&#8217;d really like to hear from you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.holygrails.net/holygrails/holygrailsnet-goes-live/feed/</wfw:commentRss>
		</item>
		<item>
		<title>stacktrace.log - everywhere</title>
		<link>http://blog.holygrails.net/grails/stacktracelog-everywhere/</link>
		<comments>http://blog.holygrails.net/grails/stacktracelog-everywhere/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 12:23:38 +0000</pubDate>
		<dc:creator>npiv</dc:creator>
		
		<category><![CDATA[gotcha]]></category>

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

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

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

		<guid isPermaLink="false">http://blog.holygrails.net/?p=3</guid>
		<description><![CDATA[I&#8217;ve noticed stacktrace.log showing up all over my system. The smart thing would have been to immediately link it to my recent surge in grails activity, but google wasn&#8217;t hinting me in this direction. The fact that these where empty files, didn&#8217;t help either.
I&#8217;d even gone as far as to write a shell script called [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve noticed stacktrace.log showing up all over my system. The smart thing would have been to immediately link it to my recent surge in grails activity, but google wasn&#8217;t hinting me in this direction. The fact that these where empty files, didn&#8217;t help either.</p>
<p>I&#8217;d even gone as far as to write a shell script called cleanStacks on my production system <img src='http://blog.holygrails.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>It turns out, this is mentioned in the grails reference however:</p>
<blockquote><p>When exceptions occur, there can be an awful lot of noise in the stacktrace from Java and Groovy internals. Grails filters these typically irrelevant details and restricts traces to non-core Grails/Groovy class packages.</p>
<p>When this happens, the full trace is always written to the StackTrace logger. This logs to a file called stacktrace.log</p></blockquote>
<p>The solution is to edit your grails-app/conf/Config.groovy, and change the line</p>
<pre class="prettyprint">StackTrace="error,stacktraceLog"</pre>
<p>to</p>
<pre class="prettyprint">StackTrace="error"</pre>
<p>I think it&#8217;s a good idea to print full stacktraces to a log file, but the problem is that the file is produced, relative to where I start tomcat from. Since I invoke tomcat restart from various paths in my production system, these files where cluttering up my system</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.holygrails.net/grails/stacktracelog-everywhere/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
