by dissenter · 18y ago · 0 comments
Now how do you propose we do that?
This is entirely the problem. The XML didn't solve anything. We still have to negotiate the terms of the transfer. We've agreed to use XML, true, but we are still at square one.
The xml solved the problem of me having to write a parser from scratch for whatever terms of transfer you come up with.
And I don't really see the downside for most applications.
S-expressions solved this problem a long time ago. (a b c) is only 57% markup. I don't think you can get much more succinct than that and still express the idea of a list.
If message size is an issue then gzip the data. Or if you have very specific needs for processing speed, look into something like Googles protocol buffers.
You are optimizing at the wrong level if you are concerned about a few extra characters in a human-readable data exchange format.
Case in point:
<table>
<tr>
<td>a</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
<td>d</td>
</tr>
</table>
vs: (table
(tr
(td a)
(td b))
(tr
(td c)
(td d)))
Perhaps the real problem is that too many people use terrible text editors. Paren-matching and auto-indentation makes writing S-expressions orders of magnitude easier, and at least a constant factor easier than writing XML.What matters is: a list of what. Telling me (5, 7,11) means nothing.
<sizes dress='5' pants='7' shoes='11' />
is what's of value.Would an sexp be terser? Sure. But not enough to matter.
(sizes (dress . 5) (pants . 7) (shoes . 11))
But in doing that, the structure really looks off, even though it's almost exactly mirroring the XML. I think this is a clue that the XML is a bit of a stretch. Much better (in Lisp code) is: (let ((sizes '((dress . 5) (pants . 7) (shoes . 11))))
; do something with sizes
...)
But I guess the real question is what this is trying to represent. If it's the sizes of various people, then the Sexps are quite simple: (sizes
(sally (dress . 5) (pants . 7) (shoes . 11))
(suzy ...)
(alice ...)
...)
Of course, this could be expressed in XML, but how to do it best? <sizes name='sally' dress='5' pants='7' shoes='11' />
<sizes name='suzy' ... />
<sizes name='alice' ... />
But then perhaps all these sizes should be wrapped in another tag: <sizes-list>
<sizes name='sally' dress='5' pants='7' shoes='11' />
<sizes name='suzy' ... />
<sizes name='alice' ... />
...
</sizes-list>
But now we're getting away from the structure we defined using S-expressions, and besides, name='...' seems to be distinctly different information from the sizes themselves, so something else is strange. Perhaps <sizes>
<sally dress='5' pants='7' shoes='11' />
<suzy ... />
<alice ... />
...
</sizes>
Well, that looks nice, and closer to what we are trying to represent, but of course it's impossible to validate (at least from what I know of XML), since the person names are not part of our schema. We'll have to do something like: <sizes>
<person name='sally'>
<dress size='5' />
<pants size='7' />
<shoes size='11' />
</person>
<person name='suzy'>
...
</person>
<person name='alice'>
...
</person>
...
</sizes>
But now we have the problem of having to place every type of clothing in our schema. We better change it some more <sizes>
<person name='sally'>
<clothing type='dress' size='5' />
<clothing type='pants' size='7' />
<clothing type='shoes' size='11' />
</person>
<person name='suzy'>
...
</person>
<person name='alice'>
...
</person>
...
</sizes>
Great! Now we have something that matches our desired structure and is easy to validate. Of course, it's much more verbose, but that made it easier to read and write, right?Part of the problem with XML is that it causes these huge debates about how to structure and name the data. Another problem is that attributes don't nest nicely; that was the main problem in this instance. In other words, XML can be used nicely to represent a tree structure and reasonably well for lists or simple associative structures. But as soon as those associative elements need to map to something more complicated, you start having issues with how best to structure everything.
With S-expressions easily able to express assoc-lists while also being trivially nestable, these issues don't come up.
If I am sending some big list many times and speed really matters, then I care, but usually I am not. Size and speed are cheap nowadays.
(let ((list (read data)))
...)
But even in Python, you could easily hack together (not recommended) something like list = ", ".join(data.split())
...
Of course, that's not robust, but the library which is robust is much simpler than the one that requires the use of a C sax parser just to be usably fast.If the argument is that XML is more human-readable, that is implying that it's being human-modified, and then XML creates more work since it's so verbose. If the verbosity is not an issue because it's auto-generated, that implies that it's not being read/modified by humans, and the whole point of using XML in the first place is lost. I just can't see any problem that XML solves that S-expressions didn't already solve in a simpler way.
You replied: OK, I'm going to send you a list using XML.
The only thing you have proved here is that your blind hatred for XML makes you unable to read and parse what is posted.
When arguing against the evils of a standardised format which there are proper parsers for everywhere, failing to parse stuff yourself is probably not on the list of things you want to do.
Plus, given that the availability of good XML parsers is one of the primary advantages claimed for XML, can anyone name some XML parsers that aren't ridiculously slow? Maybe I haven't looked hard enough, but I always seem to find that my own code to parse ad-hoc formats goes 10x faster than, e.g., expat parsing XML.
No I didn't. Because that's exactly what the guy in the OP said. Agree on a XML schema for the data. After you've done that, writing some simple Xpath to get your data is done in minutes.
The only times my XML code is 100% DOM is when I need to make things from scratch or do XML data manipulation.