Live data from Hacker News

Don't Invent XML Languages (2006)

tbray.org

41–50 of 99 posts

Re: Don't Invent XML Languages (2006)

#41
post #12

2006, well into the era of XML being the trendy fad that every piece of Serious Business software was supposed to use. Now 18 years later, JSON seems to have displaced it. Personally, I've never found text-based formats to be a good choice for data that humans will rarely need to read or write; I much prefer simple and efficient binary formats, which can be just as extensible without the additional inefficiency and n…

In my experience people read the JSON output of things more often than anything else in both development and in maintenance. You can certainly make a point about that being stupid, and it certainly also is stupid. It just seems to be what happens when you have a gazillion APIs and even more business processes and a lot of people who should know what they are doing, who don’t. I recently had the joy of reverse enginee…

Sad applause...

Re: Don't Invent XML Languages (2006)

#42

This is less about hating on XML and more about not reinventing the wheel. I quite like XML. Things like xpath make working with it, or getting data from it much easier than JSON; though I love jq syntax and can't wait until it starts being incorporated into languages. I don't even mind xslt provided it's not being over used.

> I quite like XML. Things like xpath make working with it

XPath is great. 1.0 anyway, after that everything but the new functions was nonsense.

But do note: XPath is not an xml dialect, it’s a non-XML DSL being applied to documents.

Re: Don't Invent XML Languages (2006)

#43

2006, well into the era of XML being the trendy fad that every piece of Serious Business software was supposed to use. Now 18 years later, JSON seems to have displaced it. Personally, I've never found text-based formats to be a good choice for data that humans will rarely need to read or write; I much prefer simple and efficient binary formats, which can be just as extensible without the additional inefficiency and n…

Configuration files as text are nicer in source control.

Re: Don't Invent XML Languages (2006)

#44
post #23
post #9

Side question: when did XML start to loose favour to JSON? Did this happen because of something in particular or was it a gradual transition?

When I was writing an xbrl-to-json library I suddenly realized that they are not perfectly transferable. XML comes from spreadsheets, and so it was the first mover. Whereas json came from key-value pairs. I think key-value pairs are much easier to picture in your mind, and for the vast majority of work people are doing, it's just simpler. I think XML is wildly complicated for simply APIs.

My experience is a bit different. I use Chameleon+xmldict to generate dozen of different JSON formats, my input being a XML template plus Chameleon templating instructions. And I have found that JSON can be 100% percent expressed from XML.

Re: Don't Invent XML Languages (2006)

#45

Earlier quoted context omitted.

> I've never found text-based formats to be a good choice for data that humans will rarely need to read or write; A computer may need to read the data millions of times, but humans only need to read it when things goes wrong. If you take the route of using a binary format, then you need to provide a robust set of tools to view, edit, debug that format. It can absolutely work, journald is binary, but has the tooling t…

Gotta agrees here. How many times a day do you get asked what data did your API send to my API? For me it’s daily. Need a format that is logged and able to be displayed in an admin UI somewhere, so a DB query is not needed to prove yes A was sent to you so if A is not in your system, then it’s an issue on the other side. I would not want to debug an API that talked to another API in binary…. I mean XML or JSON is sti…

I agree with the high level point, but I’m not sure I have similar experiences. No system I’ve worked on has ever directly logged over-the-wire bytes (for obvious privacy reasons), so really the protocol can be binary. In fact, for years now most of my work has been with ProtoBufs, which has amazing tooling and an oft-forgotten text format for us mortals.

Re: Don't Invent XML Languages (2006)

#46
post #9

Side question: when did XML start to loose favour to JSON? Did this happen because of something in particular or was it a gradual transition?

You may enjoy this podcast episode, which tells the story of the inventor of JSON: https://corecursive.com/json-vs-xml-douglas-crockford/

+1 to this podcast, it sheds a ton of light on exactly how we ended up with JSON taking the wheel. Listened to it on a flight from Stockholm back to Helsinki and arrived a marginally better programmer as a result of it.

Re: Don't Invent XML Languages (2006)

#47

2006, well into the era of XML being the trendy fad that every piece of Serious Business software was supposed to use. Now 18 years later, JSON seems to have displaced it. Personally, I've never found text-based formats to be a good choice for data that humans will rarely need to read or write; I much prefer simple and efficient binary formats, which can be just as extensible without the additional inefficiency and n…

> Now 18 years later, JSON seems to have displaced it.

More like, the people who didn't understand XML was designed to simplify HTML's SGML serialization moved elsewhere to misuse JSON (and YAML, and other things), the use cases and limitations of which they also failed to understand.

From the XML spec (edited by Tim Bray, the author of the linked blog):

> XML is a subset of SGML that is completely described in this document. Its goal is to enable generic SGML to be served, received, and processed on the Web in the way that is now possible with HTML. [1]

[1]: https://www.w3.org/TR/1998/REC-xml-19980210.html

Re: Don't Invent XML Languages (2006)

#48
post #23

Earlier quoted context omitted.

When I was writing an xbrl-to-json library I suddenly realized that they are not perfectly transferable. XML comes from spreadsheets, and so it was the first mover. Whereas json came from key-value pairs. I think key-value pairs are much easier to picture in your mind, and for the vast majority of work people are doing, it's just simpler. I think XML is wildly complicated for simply APIs.

XML comes from spreadsheets?

It doesn’t.

Re: Don't Invent XML Languages (2006)

#49
I love listening to young developers guess at the history of XML, and why it was "complex" (it wasn't), and then turn around an reinvent that wheel, with every bit of complexity that they just said they didn't like... because it's necessary.

So a bit of history from someone who was already developing for over a decade when XML was the new hotness:

The before times were bad. Really bad. Everybody and everything had their own text-based formats.[1] I don't just mean a few minor variants of INI files. I mean wildly different formats in different character encodings, which were literally never provided. Niceties like UTF-8 weren't even dreamt of yet.

Literally every application interpreted their config files differently, generated output logs differently, and spoke "text" over the network or the pipeline differently.

If you need to read, write, send, or receive N different text formats, you needed at least N parsers and N serializers.

Those parsers and serializers didn't exist.

They just didn't. The formats were not formally specified, they were just "whatever some program does"... "on some machine". Yup. They output different text encodings on different machines. Or the same machine even! Seriously, if two users had different regional options, they might not be able to share files generated by the same application on the same box.

Basically, you either had a programming "library" available so that you could completely sidestep the issue and avoid the text, or you'd have to write your own parser, personally, by hand. I loooved the early versions of ANTLR because they made this at least tolerable. Either way, good luck handling all the corner-cases of escaping control characters inside a quoted string that also supports macro escapes, embedded sub-expressions, or whatever. Fun times.

Then XML came along.

It precisely specified the syntax, and there were off-the-shelf parsers and generators for it in multiple programming languages! You could generate an XML file on one platform and read it in a different language on another by including a standardised library that you could just download instead of typing in a parser by hand like an animal. It even specified the text encoding so you wouldn't have to guess.

It was glorious.

Microsoft especially embraced it and to this day you can see a lot of that history in Visual Studio project files, ASP.NET web config files, and the like.

The reason JSON slowly overtook XML is many-fold, but the key reason is simple: It was easier to parse JSON into JavaScript objects in the browser, and the browser was taking off as an application developer platform exponentially. JavaScript programmers outnumbered everyone else combined.

Notably, the early versions of JSON were typically read using just the "eval()" function.[2] It wasn't an encoding per-se, but just a subset of JavaScript. Compared to having to have an XML parser in JavaScript, it was very lightweight. In fact, zero weight, because if JavaScript was available, then by definition, JSON was available.

The timeline is important here. An in-browser XML parser was available before JSON was a thing, but only for IE 5 on Windows. JSON was invented in 2001, and XMLHttpRequest become consistently available in other browsers after 2005 and was only a standard in 2006. Truly universal adoption took a few more years after that.

XML was only "complex" because it's not an object-notation like JSON is. It's a document markup language, much like HTML. Both trace their roots back to SGML, which dates back to 1986. These types of languages were used in places like Boeing for records keeping, such as tracking complex structured and semi-structured information about aircraft parts over decades. That kind of problem has an essential complexity that can't be wished away.

JSON is simpler for data exchange because it maps nicely to how object oriented languages store pure data, but it can't be readily used to represent human-readable documents the way XML can.

The other simplification was that JSON did away with schemas and the like, and was commonly used with dynamic languages. Developers got into the habit of reading JSON by shoving it into an object, and then interpreting it directly without any kind of parsing or decoding layer. This works kinda-sorta in languages like Python or JavaScript, but is horrific when used at scale.

I'm a developer used to simply clicking a button in Visual Studio to have it instantly bulk-generate entire API client libraries from a WSDL XML API schema, documentation and all. So when I hear REST people talk about how much simpler JSON is, I have no idea what they're talking about.

So now, slowly, the wheel is being reinvented to avoid the manual labour of RETS and return to machine automation we had with WS-*. There are JSON API schemas (multiple!), written in JSON (of course), so documentation can't be expressed in-line (because JSON is not a markup language). I'm seeing declarative languages like workflow engines and API management expression written in JSON gibberish now, same as we did with XML twenty years ago.

Mark my words, it's just a matter of time until someone invents JSON namespaces...

[1] Most of the older Linux applications still do, which makes it ever so much fun to robustly modify config files programatically.

[2] Sure, these days JSON is "parsed" even by browsers instead of sent to eval(), for security reasons, but that's not how things started out.

Re: Don't Invent XML Languages (2006)

#50
post #12

2006, well into the era of XML being the trendy fad that every piece of Serious Business software was supposed to use. Now 18 years later, JSON seems to have displaced it. Personally, I've never found text-based formats to be a good choice for data that humans will rarely need to read or write; I much prefer simple and efficient binary formats, which can be just as extensible without the additional inefficiency and n…

In my experience people read the JSON output of things more often than anything else in both development and in maintenance. You can certainly make a point about that being stupid, and it certainly also is stupid. It just seems to be what happens when you have a gazillion APIs and even more business processes and a lot of people who should know what they are doing, who don’t. I recently had the joy of reverse enginee…

The decision to lock down JSON without comments was a good one, stopped all these proxy languages developing in it, like what happened with XML.
Post reply on HN