More on Perl and XML

ziggy on 2006-10-06T01:47:31

As I mentioned in my previous post, using XML to avoid writing a parser is a bad thing to do.

This reminds me of a conversation I had with gnat many years ago. He asked why Perl was always lagging behind in its XML support, since Java was all over XML, and everything was moving over to XML faster than light speed. My response was that perhaps this was just a sign that Perl doesn't need bleeding edge XML support because Perl isn't used in the places where everything is moving to XML.

At the surface, that explanation seems right. Perl has always been strongly associated with system administration, and system administration is one of those domains that's XML hostile. (and for good reason; where's the benefit?) Perl is also very good at slicing and dicing raw text (like log files, random bits of malformed HTML, nm output, whatever), so it doesn't need everything shoved into an XML format just to avoid writing a parser or using a regex.

Now, ~6 years later, the answer is clearer. Perl doesn't cleave tightly to XML because it doesn't need to.

If you look at how XML is abused as a means to avoid writing a parser, one of the most common abuses is as a means to add a measure of dynamism to languages like Java. Perl doesn't need to do that, because it's a dynamic language. Need to extend a class with a new method? Just do it. No need to implement a forrest of classes just to use XML to pick one and reconfigure it on the fly.

Another common XML abuse: serialization. If you have no natural means of representing data, XML is as good as anything. More readable ASN.1 or other binary representations. Not as terse or as clear as JSON or YAML. But if you have a natural way evaluate expressions (like, say, eval), then all that's necessary is a module to serialize data in a manner that plugs into the evaluator (like, say Data::Dumper). Sure, this is a means of using eval to avoid writing a parser, but doesn't require using XML just to avoid writing a parser. (This may not be a bad thing; Lispers have done this for decades.)

So, Perl and XML aren't joined at the hip simply because they don't need to be.