My #MAUI Day talk - part 1

My #MAUI Day talk - part 1

This is a summary of part 1 of the talk I gave at #MAUIDay last week.


XAML is the default option for defining UIs in MAUI (and WinUI, WPF, & UWP) yet everyone seems to agree that XAML is far from great. It can be verbose, hard to read, hard to understand, and hard to maintain.

Lots of people complain about it, but no one does anything about it.*


If it's so bad as to be worth repeatedly complaining about:

  • Maybe the solutions are so obvious to everyone else that it doesn't even need saying. But, if that's the case, why does everyone: complain, write objectively bad (I said "poopy" in my talk) code, and write code that looks like it could have been written 18+ years ago?
  • Maybe the complaints aren't real; people just like complaining, and XAML got the short straw when it came to choosing what everyone should moan about. But that can't be the case, as it is objectively bad.
  • Maybe what I see as bad is "good enough" for everyone else. But if that's the case, why all the complaints?

Surely I can't be the only one who sees the issues and has thought about doing things differently?

If that's the case, it's a very scary thought.


XAML has been used by hundreds of thousands of people since it came out in 2006 (for building WPF apps) and little has changed since then:

  • The books from that time are still mostly relevant.
  • The examples from that time are still mostly relevant.
  • The way it is taught has not changed since that time.


Are there other languages that are actively encouraged to be used and have seen so little development in almost 20 years?

Imagine trying to use a 19-year-old book on C# today!


It's not just that there are no new versions, it's that the way we think about it hasn't changed. When every other aspect of technology is evolving and being updated at a great pace, why has something that we all know to be bad not been given any consideration to how it could even be used in better ways?


How do people justify choosing to use this technology today?

If an employee or co-worker told me, "We're going to use X technology, we know it's not great, and we make fun of how bad it is, but we're going to use it anyway." it would raise some serious red flags:

  • Why are you using it?
  • What are the alternatives?
  • Are there ways it can be used that address some of the problems?
  • What other decisions have you made with the same justification?
  • Why is this acceptable?


Developers are supposed to be smart people. Does this seem smart?



*Some people (probably between 6 and 12% of MAUI developers) have decided to abandon XAML and use C# instead.

The argument goes something along the lines of "XAML is bad, but I like C#; why don't I [or we] just use C# for everything."

It's a reasonable argument and certainly possible, but I don't think it's the silver bullet that some claim:

  • Most UIs defined in C# (all examples I've seen) adopt the same structures, patterns, and mistakes seen in XAML files. The code is basically the same as the equivalent XAML. Just because it's a different syntax, doesn't make it better.
  • Claims of a "fluent interface" are exaggerated due to the use of method chaining for some functionality. In reality, the need to combine setting some properties directly, setting some properties via chained methods with the property name, setting some properties via a chained method with a different name, and having to rely on massively overloaded fallbacks for some functionality means you can only really be fluent if you're very familiar with all the options and which to use when.
  • That C# is "easier" and has "helpers" available ignores the fact that XAML can be written to be "easier" to read and helpers can be created to work with it too.
  • Claims that the use of C# creates a faster application than using XAML, ignores the benefits, of using compiled XAML. More importantly, the performance of code is often down to the way it's written and used, rather than an underlying benefit. I've not seen these performance claims backed up with real data to show the benefit, and people arguing this position don't seem as concerned with optimizing every aspect of their code for performance. If performance is a problem or is critical to an application, then, of course, you should do what's necessary to produce software that performs adequately. If you claim to make a decision for performance reasons but don't measure performance or optimize for performance consistently, I don't consider it a good argument.
  • That C# needs to use fewer "magic strings" ignores that there are ways to remove the need to use any kind of "magic value" in most XAML scenarios and that most C# code (including demos and reference examples) is littered with "magic numbers".
  • One argument for using XAML is that it encourages the separation of logic from presentation code. Though it's possible to maintain this separation when using C# for everything, it can lead to more complex code, and the effort required to separate things means it is rarely done.
  • Even if everyone did decide to switch to using C#, does that mean they need to rewrite all their existing XAML? Would that be the best use of people's time? Would everyone be able to do this confidently because they have good UI test coverage and so could avoid introducing any unintended changes while doing the rewrite? - No!
  • And if using a single language for everything is so great and such a wonderful solution, why don't we see this elsewhere on other platforms and with other technologies? For the people switching to Blazor because they don't like XAML, they still use HTML and C#. Why is almost all web development done with at least three languages (HTML, JS, & CSS)?


I'm not going to stop anyone from using C# for their UIs. In fact, I use it for some things myself. When there is logic required in determining what the UI should look like or be comprised of, using C# can be much more productive and performant than trying to do everything in XAML.

There was never meant to be a decision between using XAML or C#. It has always been the case that you get the best results when you use both. XAML and C# work together.


Of course, if the tools and languages you're using to create your app UIs are as good as you need and can imagine, and you're super productive, and couldn't possibly get any better, keep doing what you're doing.

I've yet to meet anyone where this is the case, and there was no one at the conference who admitted to this situation either.


I was worried I was "bringing sand to the beach" to present these ideas to a room full of experts and highly experienced individuals who work with XAML on a regular basis.

Sadly, I'm still to find others who are not writing the same bad XAML as everyone else.



Now enjoy Part 2, where I show that many of the issues people have with using (writing, reading, understanding, and modifying) XAML are actually down to how they use it and because they don't treat it like code.


paramjit singh

Founder at Jugti Tech

4 天前

Even if we neglect the other benefits of c# ui the time and effort saved in not learning XAML is a good reason to only use c# for UI

回复

要查看或添加评论,请登录

Matt Lacey的更多文章

  • Why do you let your developers use XAML?

    Why do you let your developers use XAML?

    Serious question. If you employ or manage developers who use XAML to develop apps (with MAUI, WPF, WinUI, UWP, or…

    13 条评论
  • My #MAUI Day talk - part 5

    My #MAUI Day talk - part 5

    This is the final part in a series recapping my talk from MAUI Day (in London). This will probably only make sense if…

  • My #MAUI Day talk - part 4

    My #MAUI Day talk - part 4

    This is part 4 in a series recapping my talk from MAUI Day (in London). This will make much more sense if you read…

  • My #MAUI Day talk - part 3

    My #MAUI Day talk - part 3

    This is part 3 in a series recapping my talk from MAUI Day (in London). This will make much more sense if you read part…

  • My MAUI Day talk - part 2

    My MAUI Day talk - part 2

    Part one is here. (You should probably read that first.

  • Improving accessibility in MAUI

    Improving accessibility in MAUI

    .NET #MAUI has an ever-improving set of tools to help build apps that are accessible to as many people as possible.

    5 条评论
  • Evaluating the use of Copilot to create unit tests for code

    Evaluating the use of Copilot to create unit tests for code

    There's an idea that is being repeated a lot that writing unit tests for code is now much easier as you can "just" have…

  • Why you need to make intuitive, six-dimensional apps

    Why you need to make intuitive, six-dimensional apps

    The following is an extract from the first chapter of ‘Intuitive UX: The Six Dimensions of Mobile User Experience’. The…

社区洞察