Live data from Hacker News

When XML Beats JSON: UI Layouts

engineering.instawork.com

231–240 of 274 posts

Re: When XML Beats JSON: UI Layouts

#231

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…

Sorry, but

    
      ...
      ...
     
is more verbose than

    new OrderedList(
      new List { 
        new ListItem(...), 
        ... 
      }
    );
??

Re: When XML Beats JSON: UI Layouts

#232

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…

- The verbosity is easily addressed by using an IDE which providing smart folding, highlighting, etc... - Editing XML is actually a lot easier than JSON. Thanks to XML schemas, completion works really well in XML and very poorly (if at all) in JSON. - Also, XML allows comments, which JSON doesn't. - You don't need `findViewById()` in 2019 and haven't in a while, really: there are plenty of alternatives available (syn…

I don't think the person you're replying to is arguing XML vs JSON as much as UI in markup vs UI in native code.

Re: When XML Beats JSON: UI Layouts

#233

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…

Ahhhh the never ending should UI live in the code, or should it live outside the code debate. There is definitely a cohort of people who find React and code based UI patterns better. There is also a cohort of people who prefer to keep the two separate. I tend to side with the former architecture, just from years of experience building software where keeping them separate actually doesn't win you anything. Yet I've met engineers who swear by XML/Interface Builder/VB style development. Hey, as long as you can build your software and get the job done and the tools are helping you get the job done, who am I to tell you what pattern to build with?!

Re: When XML Beats JSON: UI Layouts

#235

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 don't agree very much with your take. - User interfaces are very prone to have big files, because there tend to be a lot of different components. I don't get how XML will add more bloat, other than having the tags for defining elements. - XAML lets you define custom controls. I'm not familiar with Android XML, but in any case it's not an issue of the language but of the framework. - Again, a fault of the framework.…

> - User interfaces are very prone to have big files, because there tend to be a lot of different components. I don't get how XML will add more bloat, other than having the tags for defining elements.

I disagree that this is an inherent property of user interfaces. In fact I think it's a bit weird that we focus so much on abstractions and when it comes to the code we write (DRY principle, etc), but then when it comes to XML we wave our hands in the air and declare "well that's just the way it has to be".

> - XAML lets you define custom controls. I'm not familiar with Android XML, but in any case it's not an issue of the language but of the framework.

Custom controls allow you to reuse entire widgets, but what about code reuse?

> - Again, a fault of the framework. Visual Studio, for example, checks your XAML for errors, both when writing and when compiling.

No, ultimately it's the fault of the fact that you're trying to shoehorn a bunch of stuff into XML attributes (as strings) that weren't strings to begin with. As I said below, ever make a typo in a binding?

> - I don't think namespaces are confusing (most programming languages have some concept of namespaces), but I agree that one could have more facilities to avoid specifying namespaces everywhere.

This is admittedly worse on Android where almost everything needs to be prefixed with android:, except stuff that comes from the support library, plus these other handfuls of exceptions (which is definitely a framework problem), but even stuff like x:Name vs Name is unnecessarily confusing in WPF.

> - Yes, but most of the time you shouldn't access the user interface from the application code, as coupling them tends to create ugly code that is prone to mistakes and failures. For me, this is an actual advantage of XML for UI, it makes it more difficult to create an interface out of spaghetti code.

That sounds good in theory. In practice, you end up with a lot of code-like constructs in your user interface. Every XAML file I've ever seen is full of bindings, converters and converter parameters, triggers, etc. You might insist this is not code because it lives in an XML file but it sure looks a lot like code to me, just shoehorned into a document language format.

In other words, while we strive hard to avoid spaghetti code, it seem like we don't apply the same principles to avoid spaghetti XML.

> - Well, one is declarative and the other one imperative. As long as you want to have both types, it doesn't matter what language you use.

False dichotomy, IMO. You can build a declarative UI in your code without resorting to XML.

> For me, there's not that much of a difference between SwiftUI/Jetpack Compose and equivalent XML code. UI definitions are going to be messy no matter what.

Have you actually worked with either of these frameworks?

Re: When XML Beats JSON: UI Layouts

#236

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…

There are languages and languages here, and your mileage will actually vary by orders of magnitude. As people already pointed, code isn't inherently declarative or non-verbose. Some of the most popular languages for creating GUIs (Java, JS, C#) aren't either. > It does not lend itself well to reuse There isn't any inherent feature for code that will enable the kind of reuse you need when declaring a GUI either. You'l…

Yes I agree that building declarative UIs in code does require language support and some languages are not well suited to it. But I think this is an area where we could see real improvement and we should want our tooling to evolve to better handle these problems.

Re: When XML Beats JSON: UI Layouts

#237
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.

Is this valid HTML, anyone?

Re: When XML Beats JSON: UI Layouts

#238
post #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.

Because sometimes you want to pass data between blobs of code, (possibly separated by time, environment or language), or even to and from humans who may not understand code.

Re: When XML Beats JSON: UI Layouts

#239

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…

What UI framework using XML is there where you can end up making silly typos that won't be caught at compile time? Or basically any sort of typo? I would expect any decent XML UI framework is going to have some sort of validation schema defined which will be quite stringent as to what is allowed at a particular level. Not that I like XML Schema.

I'm only familiar with XAML+WPF+C#+VS.

One particular pet peeve of mine is the fact that it won't catch typos in data binding. If I have IsEnabled={Path IsEnabeld} in my XAML, the designer won't catch it. At runtime, the error is silently ignored. It just doesn't work, and no tooling, nothing other than triple checking every line of code will catch it.

Also it's really bad about picking up dependencies cross package, although it might be a problem in my org's config.

Re: When XML Beats JSON: UI Layouts

#240

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…

- The verbosity is easily addressed by using an IDE which providing smart folding, highlighting, etc... - Editing XML is actually a lot easier than JSON. Thanks to XML schemas, completion works really well in XML and very poorly (if at all) in JSON. - Also, XML allows comments, which JSON doesn't. - You don't need `findViewById()` in 2019 and haven't in a while, really: there are plenty of alternatives available (syn…

I'm definitely not advocating for JSON here, that would be even worse.
Post reply on HN