2 ms·
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
by jiggawatts 3y ago
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.
- jeremyjh 3y agoThis is an excellent summary and expresses many things I've thought about when these topics come up. I entered industry in 1998 and didn't understand as well what was happening while it was happening, but came to similar conclusions looking back on it. > 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. One issue with that was a lot of developers never had any understanding of what was actually happening when they used wsdl.exe or the Visual Studio GUI to do that. Funny story: a partner we work with now gave us a SOAP API to consume that just about had to have been developed by one of these idiots. Most of the payload was XML content that fit different schemas depending on the transaction type. They didn't know how to model this properly so they just had a content node whose contents were a string that contained escaped XML; exactly what would happen if you were told to make content dynamic and didn't know anything about XML but only how to use the serialized objects in C#: you have an object with a content property that is a string, and you just put arbitrary XML into that string. So you'd get these API responses that were clearly formatted SOAP envelope and then Bespoke Envelope and then unreadable gibberish littered with > < etc.
- tootie 3y agoBack in 2005-10 era, we used to use stuff like XMLBeans to define an entire, consistent domain model include type constraints (enums, valid integer ranges, regex) in XML and generate code at build-time that we never had to look at. The XSD made sure it would be valid. So many years into the future and things are just worse than that.