NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed. (sponsored)
In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.
Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.
Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
In the last few months you have probably come across an article on a webzine or magazine that talks about dynamic languages, on how "Ruby on Rails" promises to boost your productivity doing webapp development opposed to the "standard" JEE way, or new features for JDK7 (like closures) or the fact that the JVM is now the host of more than 200+ languages besides Java. It turns out Groovy is one such language. But aside from receiving its fare share of publicity like other languages such as JRuby, Jython or Scala, it also has great integration with the Java language itself, as well as features found in those previously mentioned languages.
Thanks, Andres, I have really wanted to see an article like this so I could get a quick taste of what is so exciting about Groovy. A lot of the smartest people I know are thinking Groovy could be "the next big thing," and I'm glad to have this chance to learn a little about it.
Thanks Rick! I must confess that when I first saw Groovy almost a year ago I didn't pay it much attention. I took a keynote and two Ruby talks from Dave Thomas at LSSS 2006 to convince me. After that Groovy was an easy choice for me because of its tight integration to the Java platform and language.
I noticed that some examples from the article are not shown as they should, the ones that include GStrings for variable interpolation, perhaps I did something wrong when formatting them, I'll take care of that next time.
> Hi Andres,
> It was a nice intro to Groovy. I have a question, how
> should we start using Groovy in our code?
>
> Is there anyone place you know who is using Groovy in
> large enterprise applications?
Hi Meera, glad you liked it. The answer to your first question is somewhat tricky. I would say that if you are on the server side Groovy can be used to encapsulate rules that change often 8kind of like an alternative to drools), Valdimier Vivien did a great presentation at JavaOne 2007 showing the power of Spring/AOP/JMX/Groovy. You can also use it to drive XML/HTML producing/consuming, take a look at XmlSlurper, XmlStreamingBuilder and MarkupBuilder. Groovy is also an excellent choice for creating DSLs, much like Ruby is.
On the desktop side you may find SwingBuilder (and its children: SwingXBuilder, JideBuilder and GraphicsBuilder), they will let you create UIs by hand (I know, shocking for the 50% of us) in a very quick and intuitive way).
I have no verifiable info on large enterprises that use Groovy, but you can ask the same question on the Groovy mailing lists, somebody will surely point you to what you are looking for. Besides IBM did announce Project Zero a while ago, which seems on the surface to be a Rails/Grails competitor but with Groovy/PHP.
The examples not being shown as they should is probably my fault. The problem is that any code that uses ${} notation gets interpreted as JSP that the server tries to execute. I probably missed some and didn't escape the $ properly. I will look into that and try to fix them.
Meera, my suggestion would be to just start using to build scripts here and there until you get a feel for it. It may also give you an idea of what kind of performance to expect. Keep in mind that Groovy is still new and has not been performance tuned and it won't be until 2.0 comes out, so it's generally significantly slower than the equivalent in pure Java. I've used it only for scripting so far and I've really enjoyed it. It's a part of my standard toolkit now. In the future I hope to do a lot more than scripting with it.
"variable interpolation"? Is that REALLY what you want to call it?
If this is referring to the $name style EL / Velocity / Freemarker / OGNL variable substitution, there are many many ways to refer to this feature in historically meaningful ways:
- macro
- templating
- variable substitution
Please people, in the same sense of "dependency injection" being a contrived, obfuscating name for "plugins", don't cloud an established, familiar way of doing things with a ridiculous term like "interpolation". Especially in an intro article.
If there is a community of people using this term in Groovy, stop using it.
Interpolation, as far as I could tell, was usually a way of projecting or estimating new values from existing ones:
Sorry, it seems I touched a nerve there. If I recall correctly "variable interpolation" was used several years ago but it seems that the most appropriate term nowadays is "variable substitution", I apologize for the confusion. I guess both terms are still valid in Spanish (in which the original text of this article was written). I'll watch out next time for a similar case.
we are heavy Groovy users here at ImaginaWorks (a Spanish software company: http://www.imaginaworks.com). We use it mainly for webapps, we have several production sites built with Grails, one of them http://groovy.org.es. But we also use Groovy in shell scripts for our mantainance tasks, database migrations, etc.
I thought I would let you know that Python is actually technically not a dynamic language. It is not static, but it is
strongly
typed. You are correct that Ruby is dynamic though.
> Please people, in the same sense of "dependency
> injection" being a contrived, obfuscating name for
> "plugins", don't cloud an established, familiar way
> of doing things with a ridiculous term like
> "interpolation". Especially in an intro article.
>
> If there is a community of people using this term in
> Groovy, stop using it.
I'm sorry this is complete and utter nonsense. The term comes from string interpolation which is a concept supported by Perl and has been around for donkeys years. It is not a "new" or "contrived" concept from the Groovy community.
If you want to learn about String interpolation in Perl here is a newbie article:
Great Andres ! Nice Intro. We are probably crossing each others articles over the net i guess In the end can Java Code and Groovy code can co exists. Like i guess the same is done with the JavaScript and Java. The same JVM takes care of the JS too. So, it would enable to get the strengths of the dynamic type language(Groovy) and strongly typed language (Java).
Also i am interested to see the business impact of Groovy and what it complements in the current technology choices.
Introduction to Groovy
URL: Introduction to Groovy
At 3:25 PM on Sep 28, 2007, Matthew Schmidt wrote:
Fresh Jobs for Developers Post a job opportunity
Read Andres' Introduction to Groovy now.
14 replies so far (
Post your own)
Thanks, Andres!
Thanks, Andres, I have really wanted to see an article like this so I could get a quick taste of what is so exciting about Groovy. A lot of the smartest people I know are thinking Groovy could be "the next big thing," and I'm glad to have this chance to learn a little about it.Rick
bestuff.com - the best stuff in the world
Re: Introduction to Groovy
Hi Andres,It was a nice intro to Groovy. I have a question, how should we start using Groovy in our code?
Is there anyone place you know who is using Groovy in large enterprise applications?
Re: Thanks, Andres!
Thanks Rick! I must confess that when I first saw Groovy almost a year ago I didn't pay it much attention. I took a keynote and two Ruby talks from Dave Thomas at LSSS 2006 to convince me. After that Groovy was an easy choice for me because of its tight integration to the Java platform and language.I noticed that some examples from the article are not shown as they should, the ones that include GStrings for variable interpolation, perhaps I did something wrong when formatting them, I'll take care of that next time.
-- Andres
Re: Introduction to Groovy
> Hi Andres,> It was a nice intro to Groovy. I have a question, how
> should we start using Groovy in our code?
>
> Is there anyone place you know who is using Groovy in
> large enterprise applications?
Hi Meera, glad you liked it. The answer to your first question is somewhat tricky. I would say that if you are on the server side Groovy can be used to encapsulate rules that change often 8kind of like an alternative to drools), Valdimier Vivien did a great presentation at JavaOne 2007 showing the power of Spring/AOP/JMX/Groovy. You can also use it to drive XML/HTML producing/consuming, take a look at XmlSlurper, XmlStreamingBuilder and MarkupBuilder. Groovy is also an excellent choice for creating DSLs, much like Ruby is.
On the desktop side you may find SwingBuilder (and its children: SwingXBuilder, JideBuilder and GraphicsBuilder), they will let you create UIs by hand (I know, shocking for the 50% of us) in a very quick and intuitive way).
I have no verifiable info on large enterprises that use Groovy, but you can ask the same question on the Groovy mailing lists, somebody will surely point you to what you are looking for. Besides IBM did announce Project Zero a while ago, which seems on the surface to be a Rails/Grails competitor but with Groovy/PHP.
Cheers,
Andres
Re: Thanks, Andres!
Andres,The examples not being shown as they should is probably my fault. The problem is that any code that uses ${} notation gets interpreted as JSP that the server tries to execute. I probably missed some and didn't escape the $ properly. I will look into that and try to fix them.
Thanks again, and I really enjoyed the article
Re: Introduction to Groovy
Thanks again, Andres.How are you or developers you know are using Groovy in their work?
I would really like to get more information even before making a case to use Groovy in front of my Manager.
Re: Introduction to Groovy
Meera, my suggestion would be to just start using to build scripts here and there until you get a feel for it. It may also give you an idea of what kind of performance to expect. Keep in mind that Groovy is still new and has not been performance tuned and it won't be until 2.0 comes out, so it's generally significantly slower than the equivalent in pure Java. I've used it only for scripting so far and I've really enjoyed it. It's a part of my standard toolkit now. In the future I hope to do a lot more than scripting with it.Re: Thanks, Andres!
"variable interpolation"? Is that REALLY what you want to call it?If this is referring to the $name style EL / Velocity / Freemarker / OGNL variable substitution, there are many many ways to refer to this feature in historically meaningful ways:
- macro
- templating
- variable substitution
Please people, in the same sense of "dependency injection" being a contrived, obfuscating name for "plugins", don't cloud an established, familiar way of doing things with a ridiculous term like "interpolation". Especially in an intro article.
If there is a community of people using this term in Groovy, stop using it.
Interpolation, as far as I could tell, was usually a way of projecting or estimating new values from existing ones:
http://en.wikipedia.org/wiki/Interpolation
As my favorite slashdot I ever read once said:
Eschew Obfuscation Assiduously
Re: Thanks, Andres!
Sorry, it seems I touched a nerve there. If I recall correctly "variable interpolation" was used several years ago but it seems that the most appropriate term nowadays is "variable substitution", I apologize for the confusion. I guess both terms are still valid in Spanish (in which the original text of this article was written). I'll watch out next time for a similar case.Re: Introduction to Groovy
Hi all,we are heavy Groovy users here at ImaginaWorks (a Spanish software company: http://www.imaginaworks.com). We use it mainly for webapps, we have several production sites built with Grails, one of them http://groovy.org.es. But we also use Groovy in shell scripts for our mantainance tasks, database migrations, etc.
Re: Introduction to Groovy
I thought I would let you know that Python is actually technically not a dynamic language. It is not static, but it is strongly typed. You are correct that Ruby is dynamic though.Re: Thanks, Andres!
> Please people, in the same sense of "dependency> injection" being a contrived, obfuscating name for
> "plugins", don't cloud an established, familiar way
> of doing things with a ridiculous term like
> "interpolation". Especially in an intro article.
>
> If there is a community of people using this term in
> Groovy, stop using it.
I'm sorry this is complete and utter nonsense. The term comes from string interpolation which is a concept supported by Perl and has been around for donkeys years. It is not a "new" or "contrived" concept from the Groovy community.
If you want to learn about String interpolation in Perl here is a newbie article:
http://www.shlomifish.org/lecture/Perl/Newbies/lecture2/interpolation.html
Re: Introduction to Groovy
Great Andres ! Nice Intro. We are probably crossing each others articles over the net i guessIn the end can Java Code and Groovy code can co exists. Like i guess the same is done with the JavaScript and Java. The same JVM takes care of the JS too. So, it would enable to get the strengths of the dynamic type language(Groovy) and strongly typed language (Java).
Also i am interested to see the business impact of Groovy and what it complements in the current technology choices.
Re: Introduction to Groovy
Anyone learning Groovy might find this search engine for Groovy code snippets useful:http://groovy-code-snippets-swicki.eurekster.com/