When XML Beats JSON: UI Layouts
At this point I am convinced that the decision to define UI layouts in XML instead of code has been a terrible mistake.<p>- For starters, it&#x27;s overly verbose. If you&#x27;ve worked with stuff like XAML in WPF or XML layouts on Android, you know how quickly those files tend to get bloated.<p>- 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 more bloat.<p>- Editing XML kind of sucks. You&#x27;re more at risk of making silly typos that won&#x27;t be caught at compile time.<p>- XML namespaces make an already verbose language even more verbose, not to mention just generally confusing.<p>- At some point you will need to access your user interface from your application code. Which means you end up with silly stuff like findViewById() to bridge the gap, adding even more boilerplate to your code.<p>- You essentially have to learn two different sets of APIs which do the same thing. <i>&lt;Button title=&quot;blah&quot;&#x2F;&gt; vs button.setTitle(&quot;blah&quot;)</i>. Why?<p>The only real strengths of XML are that 1) it&#x27;s declarative, 2) it&#x27;s hierarchical, and 3) it&#x27;s diffable. But code can be too, without all of these other drawbacks.<p>Fortunately it seems like the industry is starting to figure this out with things like SwiftUI and Jetpack Compose. I really think we&#x27;re going to look back in a few years and think it was ridiculous that we used to do this stuff in XML.