Tuesday, February 24, 2009

XML is not a Programming Language

I've said this many many times before, but I don't think I've ever put it so eloquently.
"The fact is, that XML is not a programming language and it should not be used as one."
- One More Commit: The Future of Java Build Tools
This goes far beyond tools like ANT, and extends into other realms such as XSLT. Have you ever tried to do anything really complicated in XSLT?

Back in 2002 I took a XML course taught by the brilliant Axel T. Schreiner. This guy is seriously smart, and I mean it. He used to teach a two-hour class about complex language theory without any notes, completely from memory. One of our tasks was to write a lexicographical bubble sort on a string using standard XSLT. I think only a few people in the entire class figured it out, and the solutions were almost impossible to understand without explanation. It was a wonderful exercise, teaching us the ins and outs of XSLT, as well as its many limitations. If it taught me one thing, however, it's that I didn't ever want to have to write XSLT Stylesheets for a living.

The verbosity of ANT leads to its own problems. I've used ANT heavily in the past, and it has huge advantages over its predicessors. Unfortunately when you start getting even mildly complex build (or other) procedures the organizational overhead is almost nightmarish. It doesn't have built in hierarchical structures, has a non-intuitive inheritance model, and the control structures leave a lot to be desired. Using it to do anything beyond simple builds is difficult, and is definitely using ANT beyond its intended scope.

The main argument I've heard for using XML as either a programming language or in configuration files is that you can deploy without compiling. I've heard this from management, SCM, and some of my fellow developers. For some reason everyone has the misconception that if you don't have to compile to deploy then it's safe. I've even seen different testing procedures put in place depending on if you're deploying compiled java code vs. XML files. This absolutely blows my mind. The idea that an interpreted language is any safer than a compiled language is absurd; if anything it's more dangerous. I can't tell you how many times I've seen a plain old XML file rushed to prod, where it quickly caused huge problems that should have been picked up with propper testing.

ANT and XSLT are very powerful for the applications that they were created to meet. Using them beyond their intended scope is giving them a bad name.

I love XML. I really do. It's a wonderful document format, and lends itself nicely to configuration files. I even think it's a great way to represent serialized objects in many cases. However, it's not the end-all solution for every problem out there. I believe it particularly fails when it's used as a base for programming languages. I really just wish people would stop trying to fit a square peg into a round hole.

No comments:

Post a Comment