

Why I hate XML for DSLs - gnosis
http://theschemeway.blogspot.com/2007/01/why-i-hate-xml-for-dsls.html

======
reeses
I have to say that I've never considered using an XML for a DSL. Most of the
reasons I've written DSLs usually involve a desire to avoid writing more code.

The closest I've come to writing an XML-like DSL are the many Lisp-lites that
I've hacked up over the years. Most of the rest are either Forthish languages
(if it's primarily for my use to avoid writing large quantities of Java, C*,
Haskell, etc.) or rough "business natural language" DSLs for power users who
want to tweak a process, object, or flow.

In general, I wouldn't even consider XML as a DSL unless I broaden my idea of
a "DSL" to mean "any representation of a state or set of operations used by a
computer," in which case I've written a lot of XSDs for machine-generated
documents, such as serialized objects, messages to be placed on ESBs or
queues, etc. But I do not think this article pertains to that sort of
"language" either.

~~~
j_baker
> I have to say that I've never considered using an XML for a DSL. Most of the
> reasons I've written DSLs usually involve a desire to avoid writing more
> code.

I'd like to ask a favor as a fellow programmer: pretend you never saw this
article. The fewer XML-based DSLs, the better.

~~~
reeses
Done! :-)

------
patrickg
I have created a programming language that is written in XML. With a decent
editor (I use oxygen xml) and a good schema (I use Relax NG) there is almost
no way to make syntax errors and typing is a breeze (auto completion). With
schematron you can even make clever (semantic) error checking before compile
time. So it always depends on the case.

~~~
j_baker
I don't doubt that you could write a DSL that someone would be productive
with. But then you'd need to keep a psychiatrist on staff to make sure the
people using it don't go crazy. If we're talking about a full on, general
purpose language, then you might as well start them on Thorazine ahead of
time. Otherwise, you risk a programmer going postal.

In short, don't risk your or your coworkers' safety. Just say no to XML as a
programming language.

~~~
patrickg
I know several people that are productive with that language without a
psychiatrist.

Take for example XSLT. You are saying that all XSLT programmers are mad?

~~~
j_baker
Not at all. However, if they enjoy it, I'm not convinced they're sane either.

~~~
patrickg
So everyone who is not mainstream is subject to not being sane? What a strange
hacker attitude...

~~~
j_baker
The point I'm trying to make is that while I'm sure you could make an XML-
based DSL that does its job, I don't think anyone would enjoy using it over an
alternate way of implementing the language. Thus, being forced to program in
it would drive them insane.

------
autarch
If you liked this blog post, you'll love mine on "Why I Hate Peanut Butter as
a Cleaning Agent".

~~~
pjscott
The difference here is that nobody is silly enough to use peanut butter as a
cleaning agent.

~~~
MindTwister
[http://cleaning.tips.net/Pages/T004197_Remove_Gum_from_Carpe...](http://cleaning.tips.net/Pages/T004197_Remove_Gum_from_Carpet_with_Peanut_Butter.html)

Sorry, I just had to find an example...

------
pak
This is exactly the sentiment that led to us at QuickFuse (quickfuseapps.com)
to skip creating yet another XML DSL for building voice apps. The voice dev
ecosystem is overflowing with them, some new and some old (VoiceXML, TwiML,
etc.), so we decided to move straight to a graphical representation that does
the task.

For some things, a visual DSL like a callflow for voice apps or musical
notation for music probably has the highest information density, and therefore
becomes the most pleasing interface for being creative.

------
mkramlich
Most of my past experience with XML reminds of a certain saying. The one about
how someone realized they had a problem and that it could be solved with XML.
Then they had two problems.

~~~
xiongchiamiov
Oh, not the one about how XML's like violence - more of it solves any problem?

~~~
furbearntrout
XML is like violence. If you see too much of it early on, you will start to
think it's normal. It will scar you for life.

------
fleitz
There are two times when you'll be better of programming in XML. One is if the
language you would otherwise be writing in is Java. (Or WCF in the MS stack)

The other is transforming XML documents (XSL) although this is quickly
becoming more of a PITA than doing it natively as the various XML APIs start
offering declarative syntaxes.

~~~
j_baker
> One is if the language you would otherwise be writing in is Java. (Or WCF in
> the MS stack)

I admit that I've never done any serious Java development, but that's jumping
from the kettle into the fire, is it not? As verbose as Java is, it seems to
be less so than XML would be.

~~~
masklinn
No, but Java is static, you have to recompile it every time you edit it. The
draw of XML-based languages for the Java community is that you don't have to
recompile them. Hell, it might even be possible to reload them on the fly.

~~~
chopin
Languages are mainly for humans, not for machines. XML is intended for
transporting data machine to machine, not to be read and comprehended by
humans. Computer languages must foster the comnprehension by (fellow)
developers, this is their main task.

Reloading is possible with Java as well. And even an XML-document has to be
reparsed and most likely be brought into an internal representation, a task
which is very similar to a compilation. So, no difference here or any
jsutification that xml is suited better for this purpose than other languages.

~~~
masklinn
> Languages are mainly for humans, not for machines. XML is intended for
> transporting data machine to machine, not to be read and comprehended by
> humans.

You might want to avoid rewriting history, or at least avoid commenting on
things you clearly know nothing about.

XML Working Group design goal 6 (out of 10):

> XML documents should be human-legible and reasonably clear.

Human readability was a primary goal of the WG, and one of the big advocacy
claims against binary or custom plaintext formats.

> Reloading is possible with Java as well.

Sure, anything's possible, you can even parse, compile and load C source code
in a Java program if you have time to waste. How many JVM implementations let
you trivially reload executed source files on the fly, and how often does that
feature explode in your face?

> And even an XML-document has to be reparsed and most likely be brought into
> an internal representation, a task which is very similar to a compilation.

The point is that it's performed on the fly, easily, and can be re-executed as
often as needed without bringing down the whole machine.

~~~
chopin
> XML documents should be human-legible and reasonably clear.

Yes, that's true, as stated in <http://www.w3.org/TR/2008/REC-
xml-20081126/#sec-origin-goals>. Nevertheless, I stand by my point that human
readability does not necessarily imply easy human comprehension. For that
matter I believe that the working group introduces that design goal to ease
problem tracking and not to imply that xml is suitable for human to human
communication (which imho should be the main design goal of computer
languages). I have great respect for your mental abilities but for me its
difficult to understand larger ant scripts as xml is a data container and not
a control flow language.

