News for hackers. Stuff that matters.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by moron4hire on Sunday July 31, 2016 @11:24AM (#12197343)
> For me the only thing that JSON got better is that JSON is directly mapped to commonly used data structures: arrays and maps.

This is nice, but it's also kind of a pain, as it makes you have to stop and think about which structured data elements it's capable of supporting and which you have to send your own metadata through the wire and then reconstruct on your own. For example: Dates. Which is a shame. If there is one data element I want the most help with serializing/deserializing, it's freaking Dates. All the other ones are super easy in comparison. There's just way to much subjective, dirty, human culture tied up in Dates.

The only thing that I think is objectively better in all cases about JSON over XML is the less verbose end-structure syntax. I think XML only has Attributes because Tags have this silly need to state their name both as they enter and exit the room.

    <Tag1 attr1="hello" attr2="world">
      <Tag2>how</Tag2>
      <Tag2>are</Tag2>
      <Tag2>you?</Tag2>
    </Tag1>
For simple, unnestable data elements, having the more efficient Attribute starts to look attractive.

If XML were more the form:

    <Tag1 attr1="hello" attr2="world">
      <Tag2>how</>
      <Tag2>are</>
      <Tag2>you?</>
    </>
It's actually only one more additional, required character to add than if the attribute value were specified as an element instead.

    <Tag1>
      <attr1>hello</>
      <attr2>world</>
      <Tag2>how</>
      <Tag2>are</>
      <Tag2>you?</>
    </>
Heck, why stop there? Do we really need to have quite all of those angle brackets now? How about we just get rid of all the ones we can assume:

    <Tag1
      <attr1 hello>
      <attr2 world>
      <Tag2 how>
      <Tag2 are>
      <Tag2 you?>
    >
And finally, who even likes angle brackets? I've never enjoyed the dual duty they play as delimiters in XML and operators in other languages. Let's use a common set delimiter, something like square brackets or maybe parentheses.

    (Tag1
      (attr1 hello)
      (attr2 world)
      (Tag2 how)
      (Tag2 are)
      (Tag2 you?))
Now where have I seen this before?

PS: JSON that is as nearly as equivalent as I can make it is not much less verbose than original XML, and requires some level of convention to make up for the differences:

    {Tag1: { attr1: "hello", attr2: "world", children: [
      {Tag2: "how"},
      {Tag2: "are"},
      {Tag2: "you?}]}
Though I'm sure in common practice it'd have a lot of the original metadata of the XML version thrown away:

    {attr1: "hello", attr2: "world", children: [
      "how",
      "are",
      "you?"]}
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mbrock on Sunday July 31, 2016 @12:42PM (#12197637)
The XML tag style is much, much easier to work with when you're dealing with markup. And XML's purpose is to be an Extensible Markup Language. It's way more appropriate than JSON or S-expressions for that.

(Do you prefer to write HTML documents as S-expressions?)

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by moron4hire on Sunday July 31, 2016 @05:05PM (#12198856)
> The XML tag style is much, much easier to work with when you're dealing with markup.

Having explicit end tags makes it harder to make well-formed documents that don't clash their closing tags.

Consider a very typical sort of HTML error:

    <table>
      <tr>
        <td>
        </tr>
      </td>
    </table>
Interleaving tags is never correct, yet XML allows us to do it (and I've seen it happen a lot).

The comparable S-Expr shows how it is just plain impossible to interleave tags:

    (table
      (tr
        (td)))
You might ask yourself, "which close paren closes which list?" if the document were particularly gnarly. But if we're talking about particularly gnarly documents, then XML can be just as ambiguous. You'd be using a text editor that highlighted matching parens for you, at that point, just as much as you'd be using one that highlights matching close- and end-tags.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by vbezhenar on Monday August 01, 2016 @04:25AM (#12200889)
This is not correct XML, parser will throw error. This is not correct HTML either. The only reason why this code is likely to produce good enough output in browser is that browser tries really hard to produce something readable even from complete garbage.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by moron4hire on Monday August 01, 2016 @06:31AM (#12201316)
Yes, I know it's not valid XML If you had read my post and not just skimmed the examples, you would have seen that was the point. XML's verbose end-tag feature makes it possible to make malformed documents in such a way that is just plain impossible with S-Expressions.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mbrock on Monday August 01, 2016 @04:29AM (#12200906)
Such interleavings can actually be valid HTML5, in that the specification defines an algorithm for parsing that handles such "tag soup" in a reasonable way.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by moron4hire on Monday August 01, 2016 @06:35AM (#12201329)
That's not the same thing as making interleaving valid.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mbrock on Monday August 01, 2016 @07:16AM (#12201522)
What's the difference?
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mbrock on Monday August 01, 2016 @03:57AM (#12200806)
I've never had trouble with that.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Sunday July 31, 2016 @04:25PM (#12198655)
> Do you prefer to write HTML documents as S-expressions?

Actually, yes. I use CL-WHO[1] a lot, in which one can write:

    (:html
     (:head
      (:title "Foo bar")
      (:link :rel "stylesheet" :href="baz.css"))
     (:body
      (:p "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Vestibulum ullamcorper efficitur purus, at suscipit nunc luctus vitae.")
      (:ol
       (:li "Cras vel est accumsan, malesuada leo eu, iaculis nulla.")
       (:li "Proin nec mi feugiat, posuere enim in, vehicula erat.")
       (:li "Morbi vitae purus nec neque posuere pharetra ultricies in nibh.")
       (:li "Nam maximus lectus faucibus, ullamcorper lectus aliquam, aliquam lectus."))))
Which I contend is prettier than the equivalent HTML.

[1] http://weitz.de/cl-who/

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mbrock on Monday August 01, 2016 @03:55AM (#12200801)
I like S-expressions too, especially when generating markup programmatically. For hand-writing HTML/XML documents, which I do quite a lot, I really enjoy the tag style because of the verbose end tags and the ease of moving blocks. It's at least nice enough to make me annoyed when people claim the tag syntax is some horrible stupid disaster compared to S-expressions or (worse) JSON.
Re:How to Avoid Being Called a Bozo When Producing XML (2005) by wtbob on Monday August 01, 2016 @04:39AM (#12200932)
> For hand-writing HTML/XML documents, which I do quite a lot, I really enjoy the tag style because of the verbose end tags and the ease of moving blocks.

I can't say anything about liking verbose tags, which seems to me a matter of taste, but moving around S-expression blocks is easy: C-SPC to set the point, M-C-f to move forward one S-expression, C-w to cut the current region, navigate to where one wants it, C-y to yank the cut region.

Granted, this is using emacs, which really had better have good S-expression-editing capabilities after 40 years!

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by mbrock on Monday August 01, 2016 @07:07AM (#12201486)
I also quite like Dylan's way of ending blocks, letting you type for example "end method do-stuff" so you can see clearly what's being ended, which is useful in a document with long sections.

And I like that XML block moving is even manageable with ed, which I actually use sometimes. Well, and vi.

Re:How to Avoid Being Called a Bozo When Producing XML (2005) by kccqzy on Sunday July 31, 2016 @01:29PM (#12197852)
Yes. With good tooling (such as Emacs), markup is much more pleasant to write in S-expressions than XML.