How can IronRuby replace XML?

Hi there,

Jimmy wrote in one of his latests posts that Ruby can replace XML. I
didn’t
understand this statement because XML files are static configuration
files
(and Ruby also has an equivalent - YAML)…

How can Ruby code replace XML files?

Thanks!
Shay.

That aspect of the blog entry was a little unclear.

I’m not a big fan of XML. XML has used for all sorts of different
purposes - object serialisation, application configuration, etc. -
although simpler alternatives exist, not all of these are completely
evil. These applications could not really be described as using XML
as dynamic language.

YAML is just another markup language and isn’t specifically associated
with ruby - there are YAML parsers for every programming language. It
can be used as a drop in replacement for these sorts of uses of XML
(object serialisation and configuration).

One application of XML that can be avoided by using ruby is msbuild.
Build scripting needs to be quick and convenient so ant, nant and
msbuild have this awkward xml based representation of tasks/targets.
If you want to extend these tools, you need to compile some code and
load it in to your build file. In this context I guess you could
describe XML being used as a dynamic language. Instead of this ugly
and awkward approach, you can use something like rake which is an
internal DSL for creating builds.

XAML is another attempt at creating a dynamic language with XML and
ASP.NET is another. Both could be replaced with a more elegant and
expressive ruby DSL.

Is that the sort of thing you had in mind Jimmy?

-----Original Message-----
From: [email protected] [mailto:ironruby-core-
[email protected]] On Behalf Of Mark R.
Sent: Tuesday, December 15, 2009 1:33 AM
To: [email protected]
Subject: Re: [Ironruby-core] How can IronRuby replace XML?

That aspect of the blog entry was a little unclear.

Sorry! Hopefully our discussions here can clear up what I meant, so I
can update the post accordingly.

One application of XML that can be avoided by using ruby is msbuild.

Is that the sort of thing you had in mind Jimmy?

Yes. I say in the post that XML has been used over and over again to add
dynamic feature to .NET and Java, and I proposed using Ruby as a much
more elegant and expressive solution.

Shay, while XML for configuration is a valid use (though, I’d argue Ruby
would make a way better configuration language =)), XML tends to contain
more than just key-value pairs that configuration is usually associated
with. Mark brought up MSBuild as an example of XML which ends up
describing a TON of behavior, which really makes it more of a
domain-specific language. This tends to be one of the great abuses of
XML which .NET developers are almost forced to use, since they don’t
have any “scripting” languages in their toolbox.

~js

because XML is often used to simulate dynamic coding a great example of
this
is XAML right?

XAML is excecutable code expressed as XML every self-respecting
enterprise
architect thinks XML is the second coming and will put loads of it in
there.
So instead of describing stuff in XML and giving your whole team carpal
tunnel you can do the same thing by using Ruby to configure your
application

The argument is often yeah we did it in XML because then we didn’t have
to
compile again to make a quick change.
The news is :slight_smile: You don’t have to compile Ruby AND you can do more stuff
with
it than you can do with XML.

Now if you were to ask me when should I use XML => when you need
validation
of data coming from an external source or when you need some form of
namespacing when communicating with 3rd parties all other cases are
YAGNI.


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Google Wave: [email protected]
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

because XML is often used to simulate dynamic coding a great example of this
is XAML right?
XAML is excecutable code expressed as XML every self-respecting enterprise
architect thinks XML is the second coming and will put loads of it in there.
So instead of describing stuff in XML and giving your whole team carpal
tunnel you can do the same thing by using Ruby to configure your application
The argument is often yeah we did it in XML because then we didn’t have to
compile again to make a quick change.

Spot on :slight_smile:

Shay, here’s a quick example of using Ruby instead of XAML:

– Thibaut

That’s a very good point though. I really never give an example of something that uses XML, and show something similar in Ruby. I’ll add that.

Switching from NAnt/MSBuild to Rake is one example that comes to my mind
:slight_smile:

Ruby is really helpful to add conditions, loops etc. Having these in
XML is really quickly hard to maintain.

– Thibaut

That aspect of the blog entry was a little unclear.

That’s a very good point though. I really never give an example of
something that uses XML, and show something similar in Ruby. I’ll add
that.

~Jimmy

And after writing all that, I saw your post Thibaut. My apologies for
repeating what you’ve already pointed out.

-Sidu

Hello Shay,

Typically XML gets to be a pain when it goes from being configuration to
a mini language. The classic example is an Ant/Nant build. The build.xml
looks real cute and readable as long as you’re doing the standard
compile → unit-test → functional-test → package flow on a toy
project. Once you’re on real-world project with a large codebase of
several thousand classes and multistage/pipelined builds, then that XML
rapidly becomes brittle, hard to change and hard to maintain.

If you examine the history of Ant/Nant, you’ll notice that over time
(due to popular demand) language constructs like branching have been
added changing the build config from a configuration to a mini DSL. But
this does not remove the basic problem - that one cannot trivially
refactor a build config that contains logic (and is thus no longer a
config) to extract abstractions and keep things civilized.

The Ruby contrast to this is Rake (not YAML directly - YAML as pure
configuration has no real advantage over XML that I’ve seen beyond being
more human readable). Rake builds pwn. Seriously. I know I’ve said this
before on this list, but I love Rake, so I’ll say it again - all .Net
and Java builds should be moved off Ant/Maven/Nant to Rake. It has none
of the limitations of an xml based build config. You can reafctor it.
You can even write tests for it, should you need to. I’ve seen it done,
and it works really well.

Is that fair example?

Cheers,
Sidu.

http://twitter.com/ponnappa

Thanks everybody for your replies!
It now makes much more sense to me. I bet that it will also make more
sense
to .NET developers once they need to decide - learn an XML DSL or a Ruby
DSL.

Thanks!
Shay.

On Tue, Dec 15, 2009 at 12:19 PM, Thibaut Barrère
<[email protected]

And after writing all that, I saw your post Thibaut. My apologies for
repeating what you’ve already pointed out.

no worries :slight_smile: More feedback is actually useful here.

– Thibaut