{"id":5178,"date":"2012-03-22T10:54:34","date_gmt":"2012-03-22T05:24:34","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=5178"},"modified":"2014-12-17T09:15:16","modified_gmt":"2014-12-17T03:45:16","slug":"writing-sentences-with-groovy-2-0","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/writing-sentences-with-groovy-2-0\/","title":{"rendered":"Writing sentences with Groovy 2.0"},"content":{"rendered":"<p>Groovy 2.0 comes with some amazing new features, which prompted a numbering scheme jump from 1.9.x to 2.0. One of the key features that I took note while going through\u00a0 <a href=\"http:\/\/glaforge.appspot.com\/article\/groovy-2-0-presentation-at-33rd-degree?utm_source=feedburner&amp;utm_medium=twitter&amp;utm_campaign=Feed%3A+glaforge+%28Guillaume+Laforge%27s+blog+feed%29\" target=\"_blank\">Guillaume Laforge&#8217;s presentation at 33rd Degree <\/a> was the support for plain language sentences made possible by optional parentheses,\u00a0 and dots.<\/p>\n<p>We love the language and we love pizza! So, I put together a small script to demonstrate the power of natural language support available on Groovy 2.0 (Tested the feature on 2.0.0-beta2).<\/p>\n<p>The PizzaDelivery takes orders and outputs the order.<\/p>\n<p>[java]<\/p>\n<p>class PizzaDelivery {<\/p>\n<p>    Integer quantity<br \/>\n    String topping<br \/>\n    Date time<\/p>\n<p>    PizzaDelivery need(Integer quantity){<br \/>\n        this.quantity = quantity<br \/>\n        return this<br \/>\n    }<\/p>\n<p>    PizzaDelivery with(String topping){<br \/>\n        this.topping = topping<br \/>\n        return this<br \/>\n    }<\/p>\n<p>    PizzaDelivery at(String time) {<br \/>\n        this.time = Date.parse(&#8216;h:mm&#8217;, time)<br \/>\n        return this<br \/>\n   }<\/p>\n<p>   String toString(){<br \/>\n        return &quot;${quantity} ${topping} at ${time.format(&#8216;h:mm&#8217;)} hours&quot;<br \/>\n   }<br \/>\n}<\/p>\n<p>PizzaDelivery pizzaDelivery = new PizzaDelivery()<br \/>\npizzaDelivery.with{<br \/>\n    need 3 with &#8216;pepperoni&#8217; at &#8216;6:00&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ need(3).with(&#8216;pepperoni&#8217;).at(&quot;6:00&quot;)<br \/>\n}<\/p>\n<p>println pizzaDelivery<\/p>\n<p>[\/java]<\/p>\n<p>This will allow us to create very simple yet elegant DSLs which would feel like English or any other language that one feels comfortable with.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Groovy 2.0 comes with some amazing new features, which prompted a numbering scheme jump from 1.9.x to 2.0. One of the key features that I took note while going through\u00a0 Guillaume Laforge&#8217;s presentation at 33rd Degree was the support for plain language sentences made possible by optional parentheses,\u00a0 and dots. We love the language and [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[7],"tags":[774,631,9,775,776,777],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5178"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=5178"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5178\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=5178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=5178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=5178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}