Earlier quoted context omitted.
You mention typical PHP projects written by people who think they know better than the likes of Tim Bray. PHP, the language that made short tags a configuration option because they wanted to mix program code with XML. PHP, the language with a lot of different escape functions because they didn't get it right the first time.
I also mentioned projects written in Ruby and Java, but that's ok. VB.Net also has XML Literals. Ha ha.
How to Avoid Being Called a Bozo When Producing XML (2005)
111–120 of 255 posts
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#112Earlier quoted context omitted.
That was not quite my point. Why pretend it is a string at all? 3 I should have been more clear. Sometimes you have these argument type deals where I would at least hope for or the monstrosity above (I assume ID=3 is not valid in hindsight, I am getting tired just writing this all on the second pass even!). And I see all different variations in the same XML file! There is no logical consistency, not even in the same…
Enclosing the attribute within double quotes isn't pre-disposing the value to be of a particular type. It's part of the XML spec that attribute values are contained within double quotes, and must be to be valid. The type isn't implied in the file. An xml schema such as could more explicitly declare the type of the value.
But this is my ignorance of XML and familiarity with HTML showing.
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#113Earlier quoted context omitted.
> I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there. On the contrary, I think that XML's bad reputation comes from the fact that it is so incredibly verbose . Also, the whole child/attribute dichotomy is a huge, huge mistake. I've been recently dealing with the XDG Menu Specification, and it contains a child/attribute design failure, one which would ha…
I think the worst of this is what I call semantic incoherence. I have a system that has things like Blah . Why is the ID, clearly always an integer in every sample of hundreds I see, represented as a string? Another favorite: [CDATA[Batchfile.bat]] , while a binary or something else will be "program.exe /argument:f /argument2:x" . By the way, this is an enterprise as it gets: a software tool from a four-letter hardwa…
You're really asking a different question here: "Why should an integer be used as a task ID?" Storing the task ID as a string may give you options in the future that you wouldn't otherwise have, at a relatively small cost in parsing performance and validation overhead.
Most of the world's regrettable XML schemas were faulty at the specification stage, not the implementation stage. To minimize the likelihood of eventual regret, I usually prefer to store stuff in strings unless there's a very good reason not to. The fact that I'm using XML means that I'm not that concerned about performance, so... strings, it is.
A similar argument can be applied to the child/attribute dilemma. If there's even the slightest chance that a field isn't always going to be a leaf node, I'll do the extra typing and make it a child. Ideally the parser would be written to make them both work the same anyway.
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#114Earlier quoted context omitted.
Alright, in the flamebait fashion, I'll bite back :) > Yeah, and how often do you merge two data formats like that into one data format in a way that doesn't require massive transformations anyway? Actually, quite a lot in the past! Back in 2009 I did some XProc pipelining of messages. These pipelines were a bit like reactive streams, which were (mostly) agnostic of the contents. This allowed me to combine, dissect a…
Okay, back to me: >Actually, quite a lot in the past! Back in 2009 I did some XProc pipelining of messages. These pipelines were a bit like reactive streams, which were (mostly) agnostic of the contents. This allowed me to combine, dissect and route streams of data in an intuitive way. Huh. So like this: |xmlstream|->|transformer|->|xmlstream| Pretty slick. So the namespacing allowed you to add new tags, without worr…
Now for the flamebait-y parts. Yes, XML has loads of archaic SGML syntax bits, DTD built-in (hopeless for small parsers) and the attribute/sub-element divide has never been completely solved. But it can be argued that JSON had a similar fate: it literally descended as a subset of ECMAscript. This also explains the lack of separation between integers and floats.
But I agree, XML is definitely not the best data-interchange format, but neither is JSON. Some LISPy syntax would be my preference for data-interchange if it needs to be readable. But I'm trying to argue that this doesn't really matter. The XML era is mostly over, and I'd say we should try to learn from 'the good parts'.
I conflated XML with the XML Schema datatypes, and I shouldn't have, but it has been some time since I last seriously worked with XML. Also, we should consider the whole ecosystem, not just structure. XML Schema actually does spec binary data (http://www.datypic.com/sc/xsd/t-xsd_hexBinary.html).
With regard to round-trips: as a general rule it might not hold if you ask me. It implies an origin and even state! Maybe the sender cannot cache your binary data for a round-trip (memory, legal, latency, security constraints all play a role here). Personally, I like RESTful for simple systems, but for more involved architectures, message passing is much more scalable and easier to distribute.
> As for parsing streaming JSON, I don't know of there are any libraries for it, but the implementation should be very simple ...
Yes, a novice programmer should be able to write it in an hour. But the weird thing is, of all our libraries and all our frameworks (browser-side), none of them do streaming. Ok, I guess we should use websockets with JSON-encoded events for this, but still.
But hey, there are so many metrics with which one can evaluate a data-interchange format. (Recently we did a survey of binary data-interchange formats and found around 25 different criteria... and we were not really being thorough).
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#115Earlier quoted context omitted.
> I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there. On the contrary, I think that XML's bad reputation comes from the fact that it is so incredibly verbose . Also, the whole child/attribute dichotomy is a huge, huge mistake. I've been recently dealing with the XDG Menu Specification, and it contains a child/attribute design failure, one which would ha…
> I think that XML's bad reputation comes from the fact that it is so incredibly verbose . > Also, the whole child/attribute dichotomy is a huge, huge mistake. Those two factors run counter to each other. Attributes decrease verbosity, compared to child elements. I agree, though. A few changes would make XML closer to ideal: eliminate attributes and eliminate the name in closing tags ( value ), which makes child elem…
Then just change '' to '(tagname,' and '' to ')' and you'll have S-expressions.
Consider this:
(feed
(version 1)
(title "Example Feed")
(link http://example.org/)
(updated "2003-12-13T18:30:02Z")
(author (name "John Doe"))
(id urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6)
(entry
(title "Atom-Powered Robots Run Amok")
(link http://example.org/2003/12/13/atom03)
(id urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a)
(updated "2003-12-13T18:30:02Z")
(summary "Some text.")))
That is a canonical S-expression (for a Scheme or Common Lisp reader, just quote the URIs too) version of:
Example Feed
2003-12-13T18:30:02Z
John Doe
urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6
Atom-Powered Robots Run Amok
urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
2003-12-13T18:30:02Z
Some text.
I particularly like how URIs are sometimes encoded as attributes and sometimes as child text elements.And compare to your proposed version:
Example Feed
http://example.org/
2003-12-13T18:30:02Z
John Doe
urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6
Atom-Powered Robots Run Amok
http://example.org/2003/12/13/atom03
urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
2003-12-13T18:30:02Z
Some text.
I think it's pretty clear which is the most readable and elegant.Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#116Earlier quoted context omitted.
> I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there. On the contrary, I think that XML's bad reputation comes from the fact that it is so incredibly verbose . Also, the whole child/attribute dichotomy is a huge, huge mistake. I've been recently dealing with the XDG Menu Specification, and it contains a child/attribute design failure, one which would ha…
> JSON has become popular because a lot of bad programmers saw nothing wrong with calling eval on untrusted input (before JSON.parse was available). Disagree. JSON became popular because it was extremely easy to implement (both for marshaling and consuming), and because it was extremely lightweight. I think you could also make the argument that JSON was conceptually easier for programmers to wrap their minds around.…
A canonical S-expression parser is strictly easier to implement, given that S-expressions consist only of lists and byte sequences (no numbers or objects), and is even more lightweight. JSON's big advantage was that it was familiar to a JavaScript programmer, that's all.
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#117Earlier quoted context omitted.
> I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there. On the contrary, I think that XML's bad reputation comes from the fact that it is so incredibly verbose . Also, the whole child/attribute dichotomy is a huge, huge mistake. I've been recently dealing with the XDG Menu Specification, and it contains a child/attribute design failure, one which would ha…
The problem is that XML maps badly to data structures in common programming languages. JSON maps perfectly to structs and datastructures as lists/arrays/maps. S-expressions are good if you work with Lisp like languages, but I don't think they're very readable if you're not into Lisp. I also can't see how they map easily into datastructures of imperative programming languages or even statically typed functional progra…
Take a look at https://news.ycombinator.com/item?id=12198581; I think it demonstrates how readable one dialect of S-expressions can be.
> I also can't see how they map easily into datastructures of imperative programming languages
JSON consists of numbers, strings, booleans, objects and arrays; canonical S-expressions consist of bytes and lists. I contend that one can easily encode strings, numbers and booleans alike as bytes, and both objects and arrays as lists. Consider:
{
"id": 1234,
"isEnabled": true,
"props": ["abc", 123, false],
}
This could be encoded in canonical S-expressions as: (object
(id "1234")
(is-enabled "true")
(props (abc "123" "false")))
Granted, one still must convert the strings "1234," "true," "123," and "false" into the expected types, but with JSON one still must check the expected types anyway; it's not that big a difference.And I honestly think that the S-expression version is far more attractive.
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#118> Don’t print > Use an isolated serializer Some old reference material (XML isn't as common as JSON anymore), but still worthwhile learning: don't output data formats directly. Directly = echo, print, printf,println...whatever your syntax suggests. I see this happen a lot with my junior engineers, and I have this same conversation with them. Prefer to use data serializers that encapsulate all the syntactical rules th…
i think a major problem is that XML kinda looks and feels like HTML (and there was the whole XHTML thing to further confuse), and outputting HTML programmatically (vs string / print / template based) has most been frowned on as overweight and cumbersome. you come from web dev doing HTML like that and you see XML and think "hey, that looks the same, i'll do it in the same way". XML is a programmatic data exchange form…
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#119Earlier quoted context omitted.
> - JSON doesn't have namespaces, making integration of different data-sources quite hard. The only reason anyone would ever say that is ... that they have used XML (or SGML) and are subscribed to that mindset. Every toplevel JSON document is a valid value in any other JSON document. That's how easy it is to integrate. The only reason that XML/SGML needs namespaces in the first place is that the schema dictates what…
I've never really subscribed to the mindset of XML for it has many disadvantages (the verbosity, the complexity of DTD, the tendency for documents which are too large). However, I do subscribe to namespaces, since it allows global referencing of names. I also do subscribe to formal grammars, mature standards, and good documentation. FYI, I've designed streaming JSON based secure messaging systems, did binary-only sch…
I have been forced to use XML one way or another for a variety of uses (mostly integration, not document storage - but still), and have not ONCE had a use for namespaces or multiple DTDs in a single document. I suspect no one has statistics, but I wouldn't be surprised if this is true for 99.9% of {users,documents,systems} - which, if true, means that 1/1000 burdens the rest needlessly. But of course, this is mere speculation.
> I also do subscribe to formal grammars, mature standards, and good documentation.
XML is enticing by appearing to have those, but it actually doesn't, as Naggum articulated in[0]. XML schemas can describe a superficial structure, but not anything non-trivial and definitely not any semantics. Naggum is entertaining though he holds nothing back, see e.g. [1].
> It's just that I think XML got an undeserved bad reputation and many of the 'good parts' have been forgotten.
The problem with XML is that, like lawyers, 95% of the population gives an undeserved bad reputation to all the rest. XML did have some good ideas, but they are almost nowhere to be find in practice.
> This allows us to connect, say, 'com.facebook:Person' with 'com.google:Person' with a global equivalence relation. It allows us to specify bridges between standards.
No it doesn't, unless they are semantically equivalent - which they never are. They might be superficially similar, with some translation possible using (e.g.) XSLT. But if, for example, com.google:Person has and no first/middle/last, and com.facebook:Person has , and (but no display name), then XSLT can only translate one way, and nothing can translate the other way without error. It's nice in theory, but - projecting from my experience which is long and across many industries, but obviously still anecdotal - in practice, the semantic differences always require logic beyond XSLT, and thus the namespaces are only of aesthetic value if any.
> It is only valid when it can be interpreted by a receiving program (otherwise it is data, not information)
True. How is that different than XML or anything else? The same statement applies to XML, namespaces or not. If the program doesn't know what it is interpreting, the namespaces do not matter. If it does know, they don't matter either. Sure, it's a way to mark the source through _all_ elements, but since the program must be aware anyway, you can just as well enclose your Person object with {Facebook: {first:'John', last:'Smith'}} or {Google: {display:'John Smith'}}. Yes, XML has a standard way of doing that - but in practice my experience that it costs about 1000 times what it provides.
> With versioning, I meant schema versioning. Admittedly, not a great solution, but at least it allows a receiving party to know which parts can safely be interpreted.
And what if semantically, the parts you don't know about make interpretation moot? Practically, if it's a version you don't know, you shouldn't try to interpret it. And that's achieved by a simple 'version' field in JSON. The standard way of doing this buys practically nothing - 99% of XML files out there do not declare or properly follow a DTD.
[0] http://www.xach.com/naggum/articles/3224504693262432@naggum.... [1] http://www.schnada.de/grapt/eriknaggum-xmlrant.html
Re: How to Avoid Being Called a Bozo When Producing XML (2005)
#120Earlier quoted context omitted.
> 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…
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?)
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.