Beauty Is in the Eye of the Beholder
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
The content has been bookmarked!
There was an error bookmarking this content! Please retry.
Posted by Floyd Marinescu, Stefan Tilkov on Dec 26, 2006
Mike also commented his own opinion that he sees JSON as a good solution for browser-server communication, "but not a serious contender for interoperability purposes...will we see JSON substituting for XML in SOAP messages, RSS feeds, etc.? Will people store JSON persistently? That will require JSON-flavored APIs, schema/'data contract' languages, query/transformation languages, apps, etc. "
- JSON took a very different approach than XML in a couple of areas: there is no version number because the spec is declared stable forever; it takes a non-draconian “be liberal in what you accept and conservative in what you produce” philosophy to be friendly to supersets (such as YAML www.yaml.org, which is big in the Ruby world)
- The JSON folks are agitating for the infrastructure vendors to support a JSONRequest API http://www.json.org/JSONRequest.html that addresses some limitations in XmlHttpRequest for AJAX environments.
Mike also commented his own opinions that while XML isn't as elegant, it is more sturdy and flexible. JSON may look simpler now but it's own limitations will become apparent once people start testing it in new scenarios. The argument that JSON is better because it is more elegant "doesn't bode well for its ultimate success" if you consider historical examples of more elegant technologies that lost to more widely adopted heavier technologies, such as LISP vs. C.
- There seemed to be a lot more JSON fans than XML fans in that thread (maybe because the original post was just a wee bit inflammatory)
- JSON may be something like 100x faster to parse than XML in today's browsers (but I doubt very much if the best JSON parsers are anywhere near that much faster than the best XML parsers ... it would be interesting to know!),
- JSON parsing ends up with something akin to a typed "business object" rather than an untyped DOM tree
- To do that in XML requires yet another layer or two of cruft (a schema and a databinding tool)
- The bottom line argument for JSON comes down to elegance -- it does what is does simply and cleanly, and simply refuses to worry about many of the things that complicate XML such as metadata (attributes), comments, processing instructions, a schema language, and namespaces.
The sweet spot for JSON is serializing simple data structures for transfer between programming languages. If you need more complex data structures (maybe with some kind of schema for validation), use XML. If you want to do full blown RPC use SOAP or XML-RPC. If you just want a light-weight format for moving data around, JSON fits the bill admirably.What do we lose from not using XML? The ability to use XML tools. If you’re someone who breathes XSLT that might be a problem; if like me your approach when faced with XML is to parse it in to a more agreeable data structure as soon as possible you’ll find JSON far more productive.
XML co-inventor Tim Bray also commented that JSON exists "to put structs on the wire", whereas: with XML "it’s assumed that you might want to stream it in by the gigabyte, or load it into one of a many different in-memory data structures, or run a full-text indexer over the contents, or render it for human consumption, or, well, anything." Tim went on further to position when ot use one vs. the other:
Sam Ruby took a closer look at the bytes going over the wire; Robert Sayre noted two advantages: As JSON is not XML, it is a lot easier to embed XML or HTML content.
- Use JSON... if you want to serialize a data structure that’s not too text-heavy and all you want is for the receiver to get the same data structure with minimal effort, and you trust the other end to get the i18n right, JSON is hunky-dory.
- Use XML if you want to provide general-purpose data that the receiver might want to do unforeseen weird and crazy things with, or if you want to be really paranoid and picky about i18n, or if what you’re sending is more like a document than a struct, or if the order of the data matters, or if the data is potentially long-lived (as in, more than seconds) XML is the way to go.
Folks tried from the beginning to make XML right for data as well as documents, and even though I think the effort made XML more useful than its predecessors, I think it's clear folks never entirely succeeded. XML is much better suited to documents and text than records and data.While claims that JSON is re-inventing XML may be debateable, it is a fact that Douglas Crockford did invent a new keyboard layout. :)
I think that both have their advantages. So why not support both? I wrote Jettison to support exactly this scenario with CXF. It is a StAX implementation which reads/writes JSON. This means you can write an XML web service and have a JSON web service with a little bit of extra configuration. It supports multiple ways of mapping JSON and XML including a simple 'mapped' convention and the BadgerFish convention as well. I have a full sample and walkthrough on my blog here if anyone is interested. There are also some more docs here for CXF JSON support.
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.
Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.
Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.
Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?
Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.
Chris Richardson shows how he ported a relational database to three NoSQL data stores: Redis, Cassandra and MongoDB.
Jean Tabaka challenges the audience to reflect on what Agile practices they are employing, how they are using them, ending with the questions “Why have their organization chosen to go Agile?
1 comment
Watch Thread Reply