News for hackers. Stuff that matters.
Re:The Emacs Problem (2005) by jerf on Thursday February 27, 2014 @08:15AM (#7311906)
Before someone jumps up and says "JSON!", bear in mind that while it's often a better format for moving data, and that the stacktrace example in that post would probably be better as JSON, that JSON does not solve the arbitrary text problem. While I'll take JSON in a heartbeat for most data serialization tasks, if you've really got mixed text, I'll take XML.
Re:The Emacs Problem (2005) by sipior on Thursday February 27, 2014 @09:26AM (#7312292)
Could I trouble you to elaborate on that a bit? I'm not sure I understand why XML would be better than JSON in that case.
Re:The Emacs Problem (2005) by chubot on Thursday February 27, 2014 @10:15AM (#7312572)
I think Steve Yegge (in another post) said it surprisingly well, and simply. Paraphrasing:

If you have more data than text, use JSON. If you have more text than data, use XML/HTML.

Imagine HTML documents encoded in JSON -- in that case JSON would be ugly and annoying to edit. Now imagine (the more common situation of) structured data serialized as XML. That is ugly and annoying to edit.

Use the right tool for the right job. :)

Re:The Emacs Problem (2005) by ygra on Thursday February 27, 2014 @10:49AM (#7312780)
The two are not interchangeable, though. XML allows mixed content, i.e. something like

    <Foo>Some text <Bar>more text</Bar></Foo>
while JSON does not. So there isn't a 1:1 mapping, at least not in the direction XML → JSON (and the other direction only works if you have a schema that defines data types for the document).
Re:The Emacs Problem (2005) by ingenter on Thursday February 27, 2014 @11:13AM (#7312940)
One can make a 1:1 mapping from XML to JSON, but it is going to be verbose.

    {
       'tag': 'Foo',
       'children': [
           'Some text',
           {
               'tag': 'Bar',
               'children': ['more text']
           }
       ]
    }
or (hello, LISP)

    ['Foo', ['Some text', ['Bar', ['more text']]]]
Re:The Emacs Problem (2005) by jerf on Thursday February 27, 2014 @12:35PM (#7313520)
Yes, that's what I mean. Both XML and JSON can ultimately encode everything, but they both do indeed have strengths over the other. The problem with XML isn't that it is a "bad thing" that should never be used, the problem is that it become trendy and people started using it for all sorts of things it shouldn't have been, combined with a healthy dose of it being used by a lot of people who didn't even understand XML. (XML isn't that complicated, but there's more to it that "tags, attributes, and text".) When you're in a domain where XML really should be used, you're going to regret trying to jam JSON into that domain.

Also, side observation, that Lisp-like encoding is pretty icky as-is (deciding if something is a tag or text by how deep the array is?), and gets worse if the XML uses attributes.

Re:The Emacs Problem (2005) by tel on Thursday February 27, 2014 @02:34PM (#7314398)
I think the various XML Schema-ifications don't help either. XML is fairly poorly defined while JSON is pretty precise. This has more to do with a heavy industry of poorly defined, implied semantics atop XML than anything about the raw format, though.
Re:The Emacs Problem (2005) by jwdunne on Thursday February 27, 2014 @04:17PM (#7315145)
Correct me if I'm wrong but I think you could get away with:

I don't think your second example is much at all like Lisp and I think to actually achieve something lispy, JSON would need some kind of symbol type, so you can do:

  ['Foo, ['Some Text', ['Bar, 'more text']]]
Though, mix in attributes, and it's just a nightmare.

After all, it's not like:

  '(Foo "Some text" (Bar "more text"))
Or with an admittedly not-very-well-thought-out attribute:

  '(Foo "Some text" (Bar ([] (name "Baz")) "more text"))
For:

  <Foo>Some text <Bar name="Baz">more text</Bar></Foo>
Though there may be a better way of representing attributes....
Re:The Emacs Problem (2005) by lisper on Thursday February 27, 2014 @02:02PM (#7314173)
That's Python. In Lisp it looks like:

'(foo "Some text" (bar "more text"))

Re:The Emacs Problem (2005) by sipior on Thursday February 27, 2014 @11:27AM (#7313040)
Thanks, chubot, I think I see the point now.
Re:The Emacs Problem (2005) by yeahbutbut on Thursday February 27, 2014 @10:04AM (#7312513)
My first thought was CDATA, but he could also mean using multiple namespaces or something else I suppose.

https://developer.mozilla.org/en-US/docs/Web/API/CDATASectio...

Re:The Emacs Problem (2005) by daGrevis on Thursday February 27, 2014 @08:26AM (#7311960)
CSON! :(