Pageant + Tortoise Mathematical Proof that Girls are Evil :)
May 16

When is Groovy (or something like it) better than XML?

Groovy, Tech Add comments

Mike has written his first bile (although a bit more tame than Hani): Groovy scripting madness – don’t get fooled!

There certainly seem to be a lot of blog entries on how XML is suddenly evil, and that we need to move to something else instead.

As with everything there are pro’s and con’s involved here.

I like Groovy when…

I really like moving away from XML as soon as I need some kind of logic. An obvious example is Ant, and the build.xml file. If you want to do a simple if() test you have to have a target which sets up properties, then have targets with the right depends=”" and if=”property”. What a hack.

I much prefer being able to have the power of a real agile language here. I can modularize my build system as much as I want (not just with <import> and co.)

I like XML when….

XML isn’t suddenly evil. It is often a good choice for a document format. We have lots of tools that can work on it, and if you keep your document fairly simple then you won’t be in tears just because it has angle brackets.

It *does* go crazy when you look at documents that use 10 namespaces, and especially when people try to write programming languages out of it!

So, in the Spring example, I agree with Mike. There isn’t enough of a difference for me to care. I don’t tear up at the sight of angle brackets, so why do something else. If the requirements change and I need to do some smart things with the xml I have the choice of:

a) Writing something that builds the xml file
b) Use something like Groovy where it kinda IS the xml file

One Response to “When is Groovy (or something like it) better than XML?”

  1. James Strachan Says:

    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”>

    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

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'cricket'