"The most valuable commodity I know of is information."

rebelutionary / 2.0

Groovy scripting madness - don't get fooled! / 2004 May 17

OK - this could be my first bile-like post.

In reading my JavaBlogs daily update mail (of course you get those don't you?) I came across Michael Henderson's post on using Groovy instead of XML to configure Spring. I thought I would investigate as we're heavy users and supporters of Spring and Groovy intrigues me (another of those cool-looking pieces of technology I've yet to find a practical use for - like JXTA and Jini).

Sadly, I was not impressed at all. While I think XML configuration files can sometimes get annoying, and removing all those lines of XML processing code is a good idea in theory, XML configuration files do have one advantage - they're readable!

As an example, compare the XML and Groovy snippets in Michael's post - they do the same Spring bean configuration.

Michael says:

This (the Groovy) seems at least as clear as the XML configuration files and a little more terse.

I say - "tell him he's dreaming" (congratulations for you Aussies out there who get the reference). A quick poll around our office shows that the XML configuration file is clearly preferred here - it's far simpler to read and understand at a glance.

Using the latest and greatest technologies for experiments is a good idea, but I feel that sometimes people bias their opinions too far in favour of the latest 'cool-tool-du-jour'. I'll stick with the XML.

Comments

Any prizes for us non-Australians who still got the reference? :)

Posted by: Alex at May 17, 2004 11:30 AM

I totally agree. I would have told the original author, but he's too much of a coward to accept comments on his blog.

If a framework requires a groovy configuration file, I couldn't use it. All my developers understand XML...

Posted by: No one at May 17, 2004 1:11 PM

Mike,
Good points, but if you want this to be a 'bile' blog....
Come on mate, put some more teeth in you blog! :)

Posted by: Mike at May 17, 2004 1:13 PM

I can't stand blogs the don't accept comments. Some needs to be able to tell them when they are driving drunk.

Posted by: Matthew Payne at May 17, 2004 1:27 PM

I think the difference in readability is only small.

But with XML you are really locked into the configuration options that the Developer gives you. With groovy, if you have to, you can do anything within the configuration.

Maybe thats not such a good thing.

Posted by: Yuri Schimke at May 17, 2004 5:38 PM

Its actually not a very good example. You could of course do the same thing in java code, and just as unreadably.

But in Groovy you can write a builder that gives you much more readable code. For example, using a builder Michael's example would look more like this (formatting sux but you should get the idea:


b = new SpringBuilder() {
bean (id:"messageSource", class:"org.springframework.context.support.ResourceBundleMessageSource") {
property(name:"basenames") {
list {
value("org/springframework/web/context/WEB-INF/${message-file}")
value("org/springframework/web/context/WEB-INF/more-context-messages")
}
}
}
}


and that *is* just as readable as the XML.

You can see more of this on the groovy dox:

http://groovy.codehaus.org/GroovyMarkup

and the AntBuilder unit tests here:

http://cvs.groovy.codehaus.org/groovy/groovy-core/src/test/groovy/util/AntTest.groovy?rev=1.8&only_with_tag=MAIN&view=markup

Posted by: Chris Stevenson at May 17, 2004 5:50 PM

FWIW it totally depends on what kind of XML config file it is. If there's a well defined schema, then XML can be a good choice.

Where XML is a lousy choice is when the XML is generic. e.g. building arbitrary beans and stuff like this


<bean class="com.acme.Foo">
<property>
<property-name>bar</property-name>
<property-value>123</property-value>
</property>
<property>
<property-name>x</property-name>
<property-value>456</property-value>
</property>
</bean>


Its often way easier to just do somethign like this in groovy...

new com.acme.Foo(bar:123, x:456)

But like anything, YMMV and choose the best tool for the job

Posted by: James Strachan at May 17, 2004 8:21 PM

It's my blog, just started it, using iBlog to post from Mac OS X and I have not set up comments yet. There is a feedback link for email.

As to the code, it was a thought experiment, a chance to try out Groovy and with the minimum amount of time invested to get it working. From the posts on serverside I could even be convinced of the pure Java route.

I simply groovy-ised the underlying Spring classes and wrote an implementation, I spent very little time considering what an elegant API for scripting would look like. I had to browse the XML parsing code to figure out how the Spring bean objects were configured and simply used those classes with only a couple of methods added.

Perhaps a documented API for configuring via JavaBeans would make the choice of configuration options XML, Java, Scripting a matter of preference.

I originally started looking at hibernate mappings since I do have a design in which end-users would be able to define new persistent types and I wanted to see if I could generate the mappng directly without creating XML. I opted for Spring configuration after deciding I could do that in less time.

I've been working with Plone/Zope/Python recently and Plone Archetypes in particular impressed me with the power of a scripting environment.

As to the blog title, see my serverside posting for an explanation.

Posted by: Mike Henderson at May 18, 2004 11:58 AM

For the case of really large configurations, hundreds of beans, typos in the XML file for a setter name etc are really annoying to discover at runtime. The eclipse plugin for spring does this type of property name validation and that really helps. However, programmatic configuration, in an IDE with code completion, for real complex cases is a good way to go, despite the readability being worse.
- Mark

Posted by: Mark Pollack at May 19, 2004 3:39 AM

I don't like using a scripting language to record relationships. relationships are best recorded as data, not code, even scripting code.
In Summary: -1
check out addtional thoughts on my blog http://www.jroller.org/page/jshingler/20040514#technology_looking_for_a_problem

Posted by: Jim Shingler at May 19, 2004 11:14 AM

Mike

Yeah, I got the reference :-) I have to start using "Tell him he's dreamin'" more often myself to stay culturally grounded...

I'm also very happy with XML personally. There's a difference between sensibly designed XML (such as Spring's IMO) and the XML hell we all endure from creatively verbose formats.

I use Eclipse/XMLBuddy (OK we can disagree about tools), and I simply don't type verbose stuff. Also we'll be able to do some cool doc generation from XML, like Howard's already done.

So we'll never discourage people from using Spring's XML formats. But there is a definite user push towards a scripting option. Is this just the coolness factor? Who knows... It's important to remember that Spring was never intended to support only one config option. So it's totally consistent without our view of the architecture to offer more options.

Rgds
Rod

Posted by: Rod Johnson at May 19, 2004 8:52 PM

anti-despressant

Posted by: anti-despressant at January 28, 2005 6:14 AM

cialis side effects

Posted by: cialis side effects at January 28, 2005 10:37 AM

Follow / ACTIVITY

About / LIFE

Atlassian

Atlassian / WORK

Photos / PERVE

Search / SEEK

Mates / BLOGROLL

Investments / FUTURE

© Mike Cannon-Brookes - 2000-2006