Live data from Hacker News

When XML Beats JSON: UI Layouts

engineering.instawork.com

161–170 of 274 posts

Re: When XML Beats JSON: UI Layouts

#161

At this point I am convinced that the decision to define UI layouts in XML instead of code has been a terrible mistake. - For starters, it's overly verbose. If you've worked with stuff like XAML in WPF or XML layouts on Android, you know how quickly those files tend to get bloated. - It does not lend itself well to reuse compared to, well, actual code. Which means there tends to be a lot of repetition. Which leads to…

I agree. I think the argument isn't json/xml/yaml/crazy it's why isn't this just code.

Re: When XML Beats JSON: UI Layouts

#162
post #64

Earlier quoted context omitted.

So Jupyter Notebooks should be XML instead of JSON. Right ?

Honestly, they should be markdown . This would also solve the versioning problem.

And where would you store the output?

R uses markdown + a separate file with the output cached and while the non-rendered file is easier to version the whole thing is a lot more difficult to handle.

Re: When XML Beats JSON: UI Layouts

#163

Earlier quoted context omitted.

Quite readable but it's a hell to parse. The first argument is the name of the element, but what is the second one? If it is a string or an array, it's the first child, but if it's an object, it's the attribute set?

Maybe something more like: [ "div", [ "The ", [ "a", { "href": "https://www.json.org/" }, [ "JSON format" ] ], " was invented by ", [ "em", "Douglas Crockford" ], "." ] ] With all children being encapsulated in an array... edit: though it again gets confusing when the 0 index is sometimes the element type and sometimes the straight text... so never mind I guess the problem persists.

How would you ever differentiate "div" from an element or text? Is "The " text or the tag?

Re: When XML Beats JSON: UI Layouts

#164
post #79

You know, when XML looks like this, I don't mind it so much: The thing is, XML in the real world never looks like this . In the real world, XML has an avalanche of obscure namespaces, weird " The simplicity of JSON is an advantage: it prevents people from mucking it up with too much nonsense like this. Of course, you CAN make unreadble JSON as well, XML just makes it so much easier.

> Fixed that for you :) https://www.youtube.com/watch?v=wA9kQuWkU7I

Such a missed opportunity to include Jim in the favorite movies examples with movies like Clear and Present Danger, Patriot Games, etc...

Re: When XML Beats JSON: UI Layouts

#165
post #158

At this point I am convinced that the decision to define UI layouts in XML instead of code has been a terrible mistake. - For starters, it's overly verbose. If you've worked with stuff like XAML in WPF or XML layouts on Android, you know how quickly those files tend to get bloated. - It does not lend itself well to reuse compared to, well, actual code. Which means there tends to be a lot of repetition. Which leads to…

I fully agree with this statement. My work is generally for the web, and HTML has the same issues. It's amazing how much removing a single tag in a nested tree can mess up VSCode's parsing engine. Just modifying the tags usually works on both open and close though.

One point I try to get across to people working on the web is that they should think of HTML as a render target, not as a layout tool.

The point of HTML isn't to make it easy to lay out a document, it's to have an easily understandable pure-text representation of hierarchical data that can be read by computers/users. Light, well-formatted, semantic HTML isn't an engineering concern, it's a UX concern.

Of course HTML can be used as a layout tool, but that's not its primarily purpose, otherwise it would include decent 2-way data bindings for tables.

Re: When XML Beats JSON: UI Layouts

#166
post #84

Earlier quoted context omitted.

{ "type": "div", "children": [ "The ", { "type": "a", "attributes": { "href": " https://www.json.org/" }, "children": [ "JSON format" ] }, " was invented by ", { "type": "a", "children": [ "Douglas Crockford" ] } ] } I think I prefer the XML :-) Edit: I agree that tagged text is a clear win for XML - for pretty much everything else I'd go for JSON. Edit2: HN ate my formatting, but probably not a bad thing ;-)

["div", "The ", ["a", {"href": " https://www.json.org/" }, "JSON format"], " was invented by ", ["em", "Douglas Crockford"], "."]

Ok, now try div

Re: When XML Beats JSON: UI Layouts

#167

Earlier quoted context omitted.

> You can't express number or array with XML Numbers can be expressed, they just have to be parsed on the client. For array, child elements are ordered and form an array naturally.

> Numbers can be expressed, they just have to be parsed on the client. But client has to know that they're numbers. So you can't just parse XML into JavaScript object without any knowledge about its structure. > For array, child elements are ordered and form an array naturally. But you can't express array of 0-length this way without explicit knowledge about structure. And you can't distinguish array of 1-length from…

> without explicit knowledge about structure

That's why XML Schema exists. So, everything you listed is possible in XML if you don't put aside some specifications on purpose.

And JSON is so self-describing that someone came with... JSON Schema.

Re: When XML Beats JSON: UI Layouts

#168
If you are going to make the case for one being better than the other then show the same data in 2 different formats side by side.

The article only shows 1 example in 1 format and then moves onto another point.

The reader is left to imagine what the difference is in their head.

Re: When XML Beats JSON: UI Layouts

#170
I really like the idea of a constrained language for UI declarations, like the angularJS/vue templates and XML instead of UI in code. It makes generating test code for the UIs tractable.

Here's my take on what's possible for generating support code for UI tests when the UI is written in a declarative, easily-parseable language: https://samsieber.tech/posts/2019/06/type-safe-e2e-testing-d...

Post reply on HN