Partager via


Rant: Xml is Code

I need to rant: If one more person brags about their class library saying "you don't have to write a line of code to do <insert cool thing here>, you just need to give it 8 pages of machine generated XML", I'm going to scream.  My perception is that these people believe "code is hard and xml is easy; so if we can transform a problem from code to xml, we make it easy". There's certainly some truth to that, but my grievance is that  XML is code:

  1. It looks like code.
  2. It acts like code.
  3. It's provably computationally equivalent to code: they're both just ASTs; they both have a syntax and semantic structure.
  4. In these cases, the XML is often sufficiently long and complicated that people want to be able to debug it and set breakpoints in it.

So let's stop pretending that it's not code. Clemen Vasters said "XML is the assembly language of Web 2.0", and I think that makes a lot of sense.

Don't get me wrong: I love XML. It solves the lexing/parsing problem, and writing parsers is annoying. And it also paves the way for more useful libraries and it lets you start dealing with data at a higher level (serialization, XSL transforms, validation, xpath queries, smart diffs, etc).  And if the choice is between 10 lines of XML or 10,000 lines of C++; then obviously I'm going to choose the XML. But by the time your XML files are so complicated that you need a tool to generate them for you and you're asking for a debugger to debug them, you've got to drop the pretense that the xml is 'easy'.

Comments

  • Anonymous
    June 27, 2006
    I'd agree that XML is code, and in most of the newer applications it's not any easier than C#.  I think the biggest opportunity that the XML provides is to think declaratively rather than imperatively.  It's not any easier, but done right, a declarative XML grammer can be much easier to understand, if not to write.
  • Anonymous
    June 27, 2006
    Mike Stall has decided to vent on Xml and picks up Clemens' quote&amp;nbsp;which I picked up on at TechEd....
  • Anonymous
    June 27, 2006
    XML is not code.  Its a markup language that relies on parser(written in code) to process/transform and present it.
  • Anonymous
    June 27, 2006
    The comment has been removed
  • Anonymous
    June 27, 2006
    You said it, man.
  • Anonymous
    June 27, 2006
    Xml is often worse than code.
    Every xml config file or whatever is DSL, for we which often we don't have a compile time checking/intellisence is limited and every time it's a new language that one has to learn.

    It's the opposite from technologies like LINQ. There the goal is to have one language.
  • Anonymous
    June 27, 2006
    Greg - XML can be declartive, but so can normal code. "code" (eg, C++/C#/perl/etc) is just a text file that requires a compiler/interpreter to process/transform it.

    What's the difference between:
      for(i = 0; i < 10; i++) print(i);

    and:
    <for iterator="i" start="0" end="0">
     <do>
       <print><expression>i</expression></print>
     </do>
     <next>
       <assign value="i">
         <add>
           <expression>i</expression>
           <expression>1</expression>
         </add>
       </assign>
     </next>
    </for>

  • Anonymous
    June 27, 2006
    Mna's got a point.  ; )
  • Anonymous
    June 27, 2006
    Strictly speaking, that's not XML. What it is is XML+some-schema-that-gives-it-the-meaning-of-a-programming-language. The only thing XML defines is the syntax, leaving all the more interesting bits to something else that might not be a formal specification at all.

    I hate to mention the language Lisp, but there are a lot of languages with Lisp like syntaxes based on s-expressions. Some of these languages are radically different in expressive power than others. Some are standards, some are not. Just because you have syntax doesn't count for much.
  • Anonymous
    June 27, 2006
    The comment has been removed
  • Anonymous
    June 27, 2006
    mschaef - you may be right on the technicalities; but the axe swings both ways:
    Strictly speaking C# files are just a text file+some-schema-that-gives-it-the-meaning-of-a-programming-language. (Where that Schema is enforced / implemented by the C# compiler).

    Imagine if all the talking heads went around saying "our library is great, you don't need to write any code, you just feed it text files through a processor [ie, a compiler]".
  • Anonymous
    June 27, 2006
    XML is the RPG of the web generation.
  • Anonymous
    June 27, 2006
    I think your example looks alot like XEXPR.  Am I correct?

    If so, that is a scripting language that uses Xml to express its syntax, but still requires a processing engine to mean anything.  And Xml is still just a loosely defined data structure.

    To stay simple, to me, code can process complex logic and work with many data types implicitly.

    I think we can go back and forth on this forever.  But to me, just like HTML is not code, XML is not code.
  • Anonymous
    June 27, 2006
    XML is not code.
    Code implies logic.
    You can have fully valid XML with no logic included in the text.
    You can not write a program that doesn't have any logic included in the text of the program.
  • Anonymous
    June 27, 2006
    "Strictly speaking C# files are just a text file+some-schema-that-gives-it-the-meaning-of-a-programming-language. (Where that Schema is enforced / implemented by the C# compiler)."


    The difference is that in the case of C#, the 'schema' of the language is part of the official definition of the language (in the case of C#, the official ECMA standard) and something you can assume as being part of a confirming C# implementation. With XML, you can't assume nearly as much: just imagine what C# would be without all that detailed thinking that went into the semantics of the language (eg: http://blogs.msdn.com/ericlippert/archive/2006/06/27/648681.aspx). There are so many details apart from the syntax that are so important, that the C# standard would be essentially vacuous if it didn't include the semantics of the language.


    In a sense, this is part of the problem your original blog post addresses (and which I agree with).  I'd argue that the cases you refer to here [1] are really just instances where you're feeling the pain caused by XML's lack of innate meaning. Since XML doesn't mean anything in and of itself, you have reimplement the whole tool chain from scratch, debugger, semantic analyzer, code generator and all.  The only thing XML bought you is  a lexer and most of a parser. Whoopee: I have an s-experession lexer and parser that are implemented in 800 lines of loose C code.


    1] " But by the time your XML files are so complicated that you need a tool to generate them for you and you're asking for a debugger to debug them, you've got to drop the pretense that the xml is 'easy'.
    "
  • Anonymous
    June 27, 2006
    The comment has been removed
  • Anonymous
    June 27, 2006
    Just because something isn't in the same class as the halting problem doesn't mean that it's not code.

    Take SQL queries for example. There's a whole field of writing and debugging them. Tell somebody who's written 10 pages of sql queries for their app that they aren't writing code, and they'll shoot you.
  • Anonymous
    June 28, 2006
    Interesting topic and good arguments.  BUT, Xml is a Markup Language and nothing more.  At best is a loosely defined database.  Where Xsd defines the Schema, Constraints, etc...

    Xslt, XPath and XEXPR (which BTW use Xml for syntax) blur the lines a bit and you could make a more valid point that expressing logic in either of those Languages MIGHT BE codeing, but you will never convince me that Xml is code.


  • Anonymous
    June 28, 2006
    The comment has been removed
  • Anonymous
    June 28, 2006
    XML can certainly contains many processing instructions which are used by the parser to affect program flow, so business logic and therefore the complexity can be moved from code to XML.
  • Anonymous
    December 13, 2006
    When people are asking for a debugger for language X, practically it means that the usage of language