6 ms·
XML Sucks (a.k.a. Why S-expressions Are Better)
- fauigerzigerk 19y agoI like s-expressions. But this guy makes a slightly odd argument that doesn't help his cause at all. He basically says XML is too complex, but s-expressions are really simple if you are an experienced lisp hacker. Otherwise, so he says, "this is going to get really hard really quickly".
- Goladus 19y agoActually he basically says XML is a complex, unpredictable mess that is not actually extensible; while s-expressions are simple, stable, and extensible. (Though extending them is still a somewhat advanced topic.)
- olavk 19y agoHe is kind of right, since he is talking a about extending the basic XML _syntax_, not about creating or extending XML vocabularies. Obviously his solution with reader macros only works in Lisp, and he seem to be proud about that, but it kind of defeats the purpose of a platform-independent exchange format.
- omouse 19y agoXML is a pain to parse properly. Have you seen how large XML libraries are? It's also complex in the fact that it adds extra bytes. Imagine a 10 Mb XML file....now figure out how much of that is space wasted on closing tags.
- olavk 19y agoXML syntax has a certain amount of redundancy. This is a feature which makes it easier to manually write or edit XML using a simple text editor, which is one of the use cases that XML was designed to support.
- bct 19y agoXML is for documents, s-expressions (or JSON or YAML or ...) is for data.
- fauigerzigerk 19y agoSo an entire HTML page is a document whereas a fragment of a page retrieved via XHR is data, right?
- bct 19y agoIf you're just going to shove it straight in the page, then it's part of a document. It's the difference between <p>here is a <a href="http://example.com">link</a>.</p> and <name>bct</name> <dob>19xx-07-03</dob> <address>...</address> One is markup, the other is something different.
- fauigerzigerk 19y agoI see what you mean but I'm not convinced that this difference merits the use of two different representations. And the difference gets blurred if you consider that XHTML makes it possible to include basically any kind of data in the document, not just elements meant to be document structure.
- bct 19y agoOh, I don't think there's anything wrong with using XML for data - it's just that these "XML sucks" rants always seem to assume that's all it's used for. I know that a JSON version of my XHTML fragment up there would suck pretty hard; would a s-exp one be any better? (honest question)
- fauigerzigerk 19y agoWhy would the JSON version of that fragment suck pretty hard? I don't think there is any rational argument for XML, JSON or s-expressions solely based on whether something is data or a document. I think to make that judgement, we need to consider things like when do we really need namespaces? How often is a particular expression written by hand, how often is it generated automatically? How important are different character encodings? Does it have to be bandwidth efficient? Is this a type of data that might actually morph into a program or is that something we want to exclude for security or complexity reasons? Are there existing tools that help us to process one or the other representation more easily? All these things depend on many more aspects than just data or document.
- olavk 19y agoXML is supposed to be a human-readable platform- and language-independent format for data and document exchange. The article just shows that you can do all kinds of cool stuff with s-expressions if you happen to use CL. Just as if a smalltalk enthusiast proposed exchange of serialized smalltalk-images as the universal solution for data interchange. Because XML is just to complex to parse.
- Tichy 19y agoDidn't read the article through to the end, but I suppose, if you can use an XML parser to read a document, you might as well use a S-Expression parser.
- omouse 19y agoJust as if a smalltalk enthusiast proposed exchange of serialized smalltalk-images as the universal solution for data interchange. That's not a bad idea, and as I understand it, the Lisp operating systems back in the day passed actual objects back and forth between programs instead of strings.
- mojuba 19y agoI raised this problem earlier on HN and never got the answer to this question: Let's say I hate XML and I love S-expressions. I'm willing to replace all my XML with Sexp now and all I need is a clearly defined syntax with charsets, escapes and all, so that I can write generators and parsers. That spec would probably fit 2 or 3 pages, but someone has to do it carefully. So where is it, the Sexp syntax for representing tree structures everybody's talking about?
- tokipin 19y agoi'm not sure what you're asking. s-exp's already represent trees: (html (head (title "hi" ) ) (body (h1 "hello" ) ) ) then (defmacro html ... ) to transform it. so lisp already has the syntax, the parsers, and the generators
- mojuba 19y agoI understand that's simple in Lisp, but I also need interoperability, and that implies different languages, among other things. Perhaps the reason nobody's adopting Sexp's is that you will never get an answer from lispers, other than "you can do it in Lisp". Great, but I need C++, Perl, then C#, Java, PHP, Python and all kinds of crappy languages to support that format.
- tokipin 19y agolisp syntax is a lot simpler than XML. a basic lisp _interpreter_ would take maybe a night or three in any language, a mere parser much less. but why you don't see many such parsers is a different issue, not closely related to s-exp's themselves
- inklesspen 19y agoSo, why _don't_ you see many such parsers?
- omouse 19y agoGreat, but I need C++, Perl, then C#, Java, PHP, Python and all kinds of crappy languages to support that format. Lucky for you, Greenspun's Tenth Rule (http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule) comes into play. All of those languages actually have Lisp embedded inside them: "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."
- axod 19y agoI like JSON. Easy to read, easy to work with.
- cmars232 19y agoI prefer JSON too.. it provides a more natural expression of associations, objects, etc. Sure, you can represent any XML/JSON in sexps, but then you have to come up with a convention, follow it, explain it, and check that its followed correctly. JSON is a precise DSL for declaring basic data structures -- semantic batteries included! Why re-invent the wheel?