Live data from Hacker News

When XML Beats JSON: UI Layouts

engineering.instawork.com

21–30 of 274 posts

Re: When XML Beats JSON: UI Layouts

#21
post #3

No one should really be writing UI code by modifying a file by hand because UIs are often complex and deep, so the file structure used to store the UI data doesn't need to be human-readable. This is true for any data - once you hit a moderate level of complexity neither JSON or XML really work - you need to build a tool to manipulate the underlying data rather than changing it directly. If you do that then it doesn't…

The other replies cover most of my reaction, but there’s one more thing I want to add:

If you have a binary format for a tree structure, you almost always end up accruing garbage as you edit it. That always happens in rich HTML editors, for example.

For something like an image editor, the bitmap is OK because it’s not a tree structure and doesn’t balloon out of control as you edit.

Where your image is tree-structured, eg Photoshop layers, the editing tool will generally show you the exact layer tree in a sidebar, so you can make sure it stays clean and tidy.

It’s easiest to keep it tidy when the canonical source is human-readable text. (Although it’s worth watching out for formatting differences. Something like gofmt helps there.)

Re: When XML Beats JSON: UI Layouts

#22
post #3

No one should really be writing UI code by modifying a file by hand because UIs are often complex and deep, so the file structure used to store the UI data doesn't need to be human-readable. This is true for any data - once you hit a moderate level of complexity neither JSON or XML really work - you need to build a tool to manipulate the underlying data rather than changing it directly. If you do that then it doesn't…

> No one should really be writing UI code by modifying a file by hand because UIs are often complex and deep

Yet people do this everyday. So it's not that complex.

Re: When XML Beats JSON: UI Layouts

#24
post #11
post #4

Earlier quoted context omitted.

so we shouldn't write HTML by hand, but instead use WYSIWYG editors?

HTML isn't a UI description. It's a document description. HTML + CSS + [browser behavior|Javascript] is the UI description, and arguably some more complex web apps are getting to the point were they've gone past the point where HTML, CSS, and JS are the best formats for describing the way they work.

They never were the best way. Other application GUI systems are less painful because they were designed for that from the beginning. HTML remains OK for documents, though.

Re: When XML Beats JSON: UI Layouts

#26
post #16

If XML is better at representing trees, and JSON is a tree, does that mean that XML is better at representing JSON than JSON?

Yes.

Consider a comparison of examples using JSON schema:

  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "Modified JSON Schema draft v4 that includes the optional '$ref' and 'format'",
    "definitions": {
        "schemaArray": {
            "type": "array",
            "minItems": 1,
            "items": { "$ref": "#" }
        }
    }
  ...


  
    Modified JSON Schema draft v4 that includes the optional '$ref' and 'format'
    
        
            array
            1
            
        
  ...
$schema and $ref are differentiated by convention in JSON, and require repeated consideration in every parsing scenario to treat them as exceptions relative to actual values within the JSON document. In the XML representation, the distinction is implicit and handled automatically for you by every parser.

Re: When XML Beats JSON: UI Layouts

#27
post #8
post #5

Earlier quoted context omitted.

Following what you say we should only have binary format. I think you underestimate the convenience of a text format. It does not only provide a simple way to generate it, but also provide a way to modify it by hand .

And have readable and understandable diffs! One of the biggest issues with the most popular 'tool-only language' (Excel) is that there is no reasonable way to audit changes. Same goes for UIs that are backed by inscrutable file formats.

Readable and understandable diffs is not a property of text files. It is very easy to design tools and formats that use text files, yet do not give you diffs that are readable or understandable.

Readability and understandability depend on more strict requirements that a text file format may or may not have. Many do, but far from all do.

For instance, JSON files do not have requirements on the ordering of keys. When making a small change to a JSON file, it is entirely legal to reorder every single key, completely destroying the diff, and an automatic tool may very well do this.

And as a counter-example, we could easily use a binary representation of JSON data, but use a diffing tool that normalises key ordering to provide diffs that are more readable and understandable than a text diff of a JSON file, even without malicious reordering of lines.

Re: When XML Beats JSON: UI Layouts

#28
I have yet to read anything that convinces me that XML is good for anything. Just because XML in certain cases is less bad than some other cherry-picked technology, doesn't mean that there aren't other better options.

See also Erik Naggum's legendary rant: https://www.schnada.de/grapt/eriknaggum-xmlrant.html

Re: When XML Beats JSON: UI Layouts

#29
XML is so awesome for UI layouts. I had a thesis that I worked on that was basically a subset of HTML (check the SMIL specification for something similar, albeit a bit more complicated, SMIL used to be a W3C recommendation).

It was so easy to understand that every person who was able to use a computer would pick it up quickly. This was not the case for HTML, my guess is because there are a ton of HTML tags and that can be overwhelming for a certain type of audience, whereas here there are at most 10 tags to learn.

The framework I'm talking about still exist, it's called XIMPEL [1] (sadly SMIL kind of died). It may seem like a weird thing, but IMO it's the only open-source framework that has an intuitive way to make non-linear storytelling easy on the web easy. People can kind of hack a choose your own adventure media story with YouTube, but XIMPEL really is so much better at it because it's actually made for that purpose. And the biggest reason why XIMPEL is simpel because it uses XML as its template language.

People just see the tags as lego blocks and build non-linear media essays, stories or even small (media-focused) games with it.

[1] http://www.ximpel.net/

Re: When XML Beats JSON: UI Layouts

#30

I have yet to read anything that convinces me that XML is good for anything . Just because XML in certain cases is less bad than some other cherry-picked technology, doesn't mean that there aren't other better options. See also Erik Naggum's legendary rant: https://www.schnada.de/grapt/eriknaggum-xmlrant.html

How about simple DSL layouts?
Post reply on HN