<?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>ThotSpots &#187; Grails</title>
	<atom:link href="http://www.thotspots.com/tag/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thotspots.com</link>
	<description>Agile Software Development</description>
	<lastBuildDate>Wed, 09 Sep 2009 18:13:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Demystifying Domain-Specific-Languages (DSL)</title>
		<link>http://www.thotspots.com/demystifying-domain-specific-languages-dsl/</link>
		<comments>http://www.thotspots.com/demystifying-domain-specific-languages-dsl/#comments</comments>
		<pubDate>Mon, 04 May 2009 01:45:47 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://www.thotspots.com/?p=194</guid>
		<description><![CDATA[Groovy supports creating Domain Specific Languages.  A DSL is simply a mini programming language tailored to a specific situation or domain.  The idea is to hide the characteristics of the underlying programming language as much as possible (in this case, Groovy/Java), and let the vocabulary of the application domain shine through.
DSLs are nothing [...]]]></description>
			<content:encoded><![CDATA[<p>Groovy supports creating Domain Specific Languages.  A DSL is simply a mini programming language tailored to a specific situation or domain.  The idea is to hide the characteristics of the underlying programming language as much as possible (in this case, Groovy/Java), and let the vocabulary of the application domain shine through.</p>
<p>DSLs are nothing new.  Just by encapsulating the concepts of a domain in classes (&#8221;domain objects&#8221;) and by defining the methods on those classes that act on them (&#8221;actions&#8221; and &#8220;messages&#8221;), you create a DSL of sorts.  You see this a lot in unit testing.  As a body of unit tests evolves, common SetUp and TearDown code is often extracted to avoid duplication.  As the extracted classes and methods grow and evolve, a DSL emerges. For an excellent example of this, see <a href="http://www.amazon.com/gp/product/0132350882?ie=UTF8&amp;tag=thotspots-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0132350882">Clean Code: A Handbook of Agile Software Craftsmanship</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=thotspots-20&amp;l=as2&amp;o=1&amp;a=0132350882" border="0" alt="" width="1" height="1" /> by Robert Martin.</p>
<p>Groovy accomplishes the creation of DSLs in a number of ways:<br />
<span id="more-194"></span></p>
<ol>
<li><strong>Optional Syntax:</strong> In Groovy, much of the syntax is optional:  semicolons at the end of statements when they are the only statement on the line, parenthesis around arguments in a method call, etc.  Dropping away such &#8220;noise&#8221; is one way that the user can then focus on the domain at hand.</li>
<li><strong>Missing-Method Methods:</strong> In Java, if you call a method that does not exist, you get a compiler error.  In Groovy, it waits until runtime to decide if it&#8217;s a problem, giving the class with the missing method a chance to make up a method on the spot.  This is done with a special &#8220;missing-method method.&#8221;  For example, this is how GORM allows you to make up method calls like findByPersonAndJobTitle().  There&#8217;s a missing-method method that knows how to parse out the name, &#8220;findByPersonAndJobTitle&#8221;  see that it&#8217;s comprised of pieces it understands (a find action and two field names) and thereby construct the logic to perform that action.</li>
<li><strong>Operator overloading:</strong> Groovy allows you to define methods that correspond to the various operators, like plus() for the + sign.  This means your DSL could allow for expression like &#8220;car = chassis + 4 * tires&#8221; and &#8220;truck = (cab + 6 * tires) + (trailer + 4 * tires) + (trolley + 4 * tires) + (trailer + 4 * tires)&#8221;</li>
<li><strong>Named Parameters:</strong> Grails has the ability to emulate named-parameters (which means that having to know the order in which to pass parameters is no longer a concern).  This is done by defining the method to accept a single map as a parameter.  Then, in the call, a map is created on the fly with hard-coded keys that look like parameter names, and expressions that are the corresponding arguments.  Leave out the optional square brackets that normally enclose a map constant, and wallah! Named parameters:</li>
<li><strong>Closures:</strong> Groovy&#8217;s strong support for Closures means it&#8217;s easy to define custom control structures</li>
<li><strong>Categories, MetaClasses, and GroovyObject:</strong> Without going into details, these are some of the core facilities in Groovy that make it a dynamic &#8220;scripting&#8221; language and so suitable for expressing DSLs</li>
</ol>
<p><strong>Builders:</strong><br />
The most common use of DSLs in Grails is the idiomatic &#8220;builder.&#8221;  This is for when there is a distinct hierarchy, or tree-structure to the elements of the domain.  There are pre-defined builders for Swing, XML, HTTP, Hibernate Criteria, HTML, ANT, and the Constraints builder in Grails that drives the validation mechanism, just to name a few.  It&#8217;s easy to create your own builders as well.</p>
<p>With the groovy.xml.MarkupBuilder(), for example, instead of having to write your own XML&#8230;</p>
<pre>&lt;stocks&gt;
  &lt;stock symbol='JAVA'&gt;
    &lt;quote day='Mon' price="53.125" /&gt;
    &lt;quote day='Tue' price="54.5" /&gt;
    &lt;quote day='Wed' price="51.75" /&gt;
  &lt;/stock&gt;
  &lt;stock symbol='MSFT' /&gt;
  &lt;stock symbol='IBM' /&gt;
&lt;/stocks&gt;</pre>
<p>You can express the information like this:</p>
<pre>builder.stocks {
    stock(symbol: 'JAVA') {
        quote(day: 'Mon', price: 53.125)
        quote(day: 'Tue', price: 54.5)
        quote(day: 'Wed', price: 51.75)
    }
    stock(symbol: 'MSFT')
    stock(symbol: 'IBM' )
}</pre>
<p>At first glance, it might seem like you&#8217;re just trading one arbitrary syntax for another: parenthesis, braces, colons and commas, rather than angle-brackets, equal signs, and  matched-up start and end tags.  However, this is merely a dumbed-down example.  The benefits of using a builder are enormous:</p>
<p>For one thing, the Builder syntax is universal.  Once you know who to write XML markup using Builder syntax, you also know how to write HTML markup, Swing forms, Grails criteria, and all of the other pre-defined builders mentioned above, and more .</p>
<p>Also, since Builder syntax is built on top of Groovy, Groovy code can be intermixed with the DSL code.  For example, we can use each-loops to build the XML markup from a &#8220;tickerInfo&#8221; object:</p>
<pre>builder.stocks {
    tickerInfo.each {ticker -&gt;
        stock(symbol: ticker.symbol) {
            ticker.dailyQuotes.each{
                quote(day: it.day, price: it.price)
            }
        }
    }
}</pre>
<p>DSLs are a key reason for the success of Grails.  Taking advantage of Groovy&#8217;s DSL support is a prime example of how much thought has gone into the architecture Grails with it&#8217;s prime directive to be as idiomatic-Grails as possible.</p>
<p>We&#8217;ve only just scratched the surface of what DSLs are and how they are supported in Groovy.  Here is some recommended further reading:</p>
<ul>
<li><a href="http://docs.codehaus.org/display/GROOVY/Writing+Domain-Specific+Languages" target="_blank">docs.codehaus.org/display/GROOVY/Writing+Domain-Specific+Languages</a></li>
<li><a href="http://docs.codehaus.org/display/GROOVY/How+Builders+Work" target="_blank">How Builders Work</a></li>
<li><a href="http://www.amazon.com/gp/product/0132350882?ie=UTF8&amp;tag=thotspots-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0132350882">Clean Code: A Handbook of Agile Software Craftsmanship</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=thotspots-20&amp;l=as2&amp;o=1&amp;a=0132350882" border="0" alt="" width="1" height="1" /> by Robert Martin</li>
</ul>
<p><strong>Related articles:</strong></p>
<ul>
<li><a href="http://www.thotspots.com/clean-code-book/" target="_blank">A brief review of <em>Clean Code</em></a></li>
<li><a href="http://www.thotspots.com/everythings-groovy/" target="_blank">Everything&#8217;s Groovy</a></li>
<li><a href="http://www.thotspots.com/ides-for-groovygrails/" target="_blank">IDEs for Groovy/Grails</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/demystifying-domain-specific-languages-dsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Everything&#8217;s Groovy</title>
		<link>http://www.thotspots.com/everythings-groovy/</link>
		<comments>http://www.thotspots.com/everythings-groovy/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 09:21:20 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Architecture and Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[web frameworks]]></category>

		<guid isPermaLink="false">http://www.thotspots.com/?p=97</guid>
		<description><![CDATA[One of the major benefits of using Grails as a web platform is how almost everything can be written in a single language &#8212; Groovy.  No more switching gears between language constructs.  Everything&#8217;s Groovy.
Groovy is most definitely the star of the Grails show.  Every decision that went into formulating Grails started with, &#8220;What&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the major benefits of using Grails as a web platform is how almost everything can be written in a single language &#8212; Groovy.  No more switching gears between language constructs.  Everything&#8217;s Groovy.</p>
<p><span id="more-97"></span>Groovy is most definitely the star of the Grails show.  Every decision that went into formulating Grails started with, &#8220;What&#8217;s the Groovy take on this? How can we best take advantage of the innate ability of Groovy to solve this?&#8221;  This attitude makes for a framework that&#8217;s powerful, yet minimal and consistent.</p>
<p>This attitude also goes beyond the Web framework.  Groovy can be used end-to-end from inside the web server pages to the outer build scripts and even your shell scripts.  In the Java world, before Grails came along, one would have to work in seven different languages to build a web app.  Grails potentially reduces that to three:</p>
<table border="1" cellspacing="1" cellpadding="1" width="90%" align="center">
<tbody>
<tr align="left" valign="top">
<th>Aspect<br/>&nbsp;</th>
<th>Any other Java Web Framework (e.g. JSP/Struts)</th>
<th>Grails Way</th>
</tr>
<tr align="left" valign="top">
<td>Business Logic</td>
<td>Java</td>
<td>Groovy</td>
</tr>
<tr align="left" valign="top">
<td>Web Pages</td>
<td>An arbitrary expression language such as EL or OGNL</td>
<td>Groovy</td>
</tr>
<tr align="left" valign="top">
<td>Data Access</td>
<td>Hibernate HQL, SQL, or Java</td>
<td>Groovy (GORM)</td>
</tr>
<tr align="left" valign="top">
<td>Client-Side Scripting</td>
<td>JavaScript</td>
<td>JavaScript</td>
</tr>
<tr align="left" valign="top">
<td>Style Sheets</td>
<td>CSS</td>
<td>CSS</td>
</tr>
<tr align="left" valign="top">
<td>Build Scripts</td>
<td>XML (Ant)</td>
<td>Groovy (GANT)</td>
</tr>
<tr align="left" valign="top">
<td>Shell Scripts</td>
<td>Linux bash scripts or Windows batch files</td>
<td>Groovy (shebang)</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/everythings-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring a Grails App for Logging</title>
		<link>http://www.thotspots.com/configuring-a-grails-app-for-logging/</link>
		<comments>http://www.thotspots.com/configuring-a-grails-app-for-logging/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 21:26:46 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.maximsc.com/configuring-a-grails-app-for-logging/</guid>
		<description><![CDATA[For any standard Grails app, the error log is called stacktrace.log by default.  On some servers, it ends up in the config folder (rather than the logs folder) by default, so it&#8217;s hard to find.  Also, with a fixed name, all apps running on the same server would share the same log.  [...]]]></description>
			<content:encoded><![CDATA[<p>For any standard Grails app, the error log is called stacktrace.log by default.  On some servers, it ends up in the config folder (rather than the logs folder) by default, so it&#8217;s hard to find.  Also, with a fixed name, all apps running on the same server would share the same log.  So, for any new Grails app, be sure to open Config.groovy and change<span id="more-49"></span></p>
<pre>
appender.'errors.File'="stacktrace.log"</pre>
<p>to</p>
<pre>
appender.'errors.File'="../logs/${appName}-errors.log"</pre>
<p><strong>Determining What is Logged</strong><br />
Config.groovy also determines what is logged.  The default logging level is error.  For some packages, you&#8217;ll want to change the logging level to warn or info.  Your choices are, in order: FATAL, ERROR, WARN, INFO, DEBUG.</p>
<p>Grails automatically generates a log4j.properties files from what&#8217;s in Config.groovy and places it in the /WEB-INF/classes folder.  The log4j.properties file can be tweaked in place as you attempt to debug a particular problem, but just remember that it gets reset every time the app is deployed.  So, permanent changes need to go in Config.groovy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/configuring-a-grails-app-for-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IDE&#8217;s for Groovy/Grails</title>
		<link>http://www.thotspots.com/ides-for-groovygrails/</link>
		<comments>http://www.thotspots.com/ides-for-groovygrails/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 22:00:21 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IntelliJ]]></category>

		<guid isPermaLink="false">http://www.maximsc.com/ides-for-groovygrails/</guid>
		<description><![CDATA[First choice: JetBrains IDEA 7.0 (with 8.0 coming shortly).  Possibly a good second choice: NetBeans 6.5 (new).  Last resort remains: Eclipse.
I used to be a big fan of Eclipse, but the Groovy/Grails support in Eclipse is sorely lacking.  Three months ago I splurged on a copy of JetBrains IDEA 7.0 (http://www.jetbrains.com/idea/index.html) and haven&#8217;t regretted it [...]]]></description>
			<content:encoded><![CDATA[<p>First choice: JetBrains IDEA 7.0 (with 8.0 coming shortly).  Possibly a good second choice: NetBeans 6.5 (new).  Last resort remains: Eclipse.</p>
<p><span id="more-48"></span>I used to be a big fan of Eclipse, but the Groovy/Grails support in Eclipse is sorely lacking.  Three months ago I splurged on a copy of JetBrains IDEA 7.0 (<a href="http://www.jetbrains.com/idea/index.html">http://www.jetbrains.com/idea/index.html</a>) and haven&#8217;t regretted it one bit.  I&#8217;m sitting on 7.0 build 7860 (&#8221;Selena&#8221;).  Since then they&#8217;ve released 7.0.4 (build 7941) and a preview of 8.0 milestone 1, but neither seem to have anything I need, so I&#8217;m sitting tight.  I am, however, anxiously awaiting 8.0 milestone 2,  which promises more Grails refactorings and support for Grails 1.0.3. (My projects are still on 1.0.2.)</p>
<p>I just saw an announcement that NetBeans 6.5 (free open source, <a href="http://www.netbeans.org/community/releases/65/">http://www.netbeans.org/community/releases/65/</a>) is in beta test and that it includes Grails/Groovy support.  For anyone doing Grails work who can&#8217;t afford IDEA, I suggest you check it out.  If you do, I&#8217;d like to hear from you.  Let&#8217;s compare notes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/ides-for-groovygrails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doin&#8217; Our Part for Grails</title>
		<link>http://www.thotspots.com/doin-our-part-for-grails/</link>
		<comments>http://www.thotspots.com/doin-our-part-for-grails/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 05:08:31 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Jasper Reports]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.maximsc.com/doin-our-part-for-grails/</guid>
		<description><![CDATA[We&#8217;ve started contributing back to the Grails open source project.  First up: furthering the cause towards an initial release of a jQuery plugin (http://www.grails.org/jQuery+Plugin).  Also, the next release of the Jasper Reports plugin (http://www.grails.org/Jasper+Plugin) should make life easier.
]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve started contributing back to the Grails open source project.  First up: furthering the cause towards an initial release of a <strong>jQuery plugin</strong> (<a href="http://www.grails.org/jQuery+Plugin#" title="jQuery Plugin for Grails">http://www.grails.org/jQuery+Plugin</a>).  Also, the next release of the <strong>Jasper Reports plugin</strong> (<a href="http://www.grails.org/Jasper+Plugin" title="Jasper Reports plugin for Grails">http://www.grails.org/Jasper+Plugin</a>) should make life easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/doin-our-part-for-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails: Ready for Prime Time</title>
		<link>http://www.thotspots.com/grails-ready-for-prime-time/</link>
		<comments>http://www.thotspots.com/grails-ready-for-prime-time/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 21:25:16 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://www.maximsc.com/grails-ready-for-prime-time/</guid>
		<description><![CDATA[I am currently leading the charge for our clients with Java-based web applications to adopt Grails (i.e. Groovy on Rails).  Grails (www.grails.org) has recently achieved its official 1.0 release, just behind the 1.5 release of Groovy.  We&#8217;re seeing a 10-fold increase in productivity by using GSP (Groovy Server Pages) over JSP (Java Server [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently leading the charge for our clients with Java-based web applications to adopt Grails (i.e. Groovy on Rails).  Grails (<a href="http://www.grails.org" target="_blank">www.grails.org</a>) has recently achieved its official 1.0 release, just behind the 1.5 release of Groovy.  We&#8217;re seeing a 10-fold increase in productivity by using GSP (Groovy Server Pages) over JSP (Java Server Pages), and that factor is only going to improve with practice, and as Grails moves beyond 1.0.<br />
<span id="more-46"></span><br />
The biggest hurdles we&#8217;ve have to overcome with Grails have all had to do with writing Grails apps against an existing database schema.  Anyone starting completely from scratch, allowing Grails to define the schema, won&#8217;t have any trouble at all.  For anyone who is about to go through what we did with a legacy schema, I&#8217;ll be writing up my notes shortly.  Look for them to be posted on our companion blog, <a href="http://www.codejacked.com" target="_blank">www.codejacked.com</a>.</p>
<p>Getting started with Grails requires two efforts: learning how Groovy extends Java, generally, and learning how Grails then takes advantage of Groovy for rapidly developing web pages.  For the former, I highly recommend the brand new book, <em>Groovy Recipes</em> by Scott Davis (Pragmatic Bookshelf).  Chapter three exactly and concisely explains what an experienced Java programmer needs to know to get started with Groovy.</p>
<p>After that, <em>The Definitive Guide to Grails</em> by Graeme Keith Rocher is probably where you&#8217;ll turn.  Be aware, though, that a second edition is pending, and you&#8217;ll want to update your copy when it comes out, so budget accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/grails-ready-for-prime-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
