Wednesday, May 09, 2018

I just "gave" a load of code to Microsoft

TLDR: Announcing a new open source project for making XAML development easier.


What's this about giving away code?

I had an idea for something, built a proof-of-concept that impressed and excited some people, and we decided that the best way to get it to lots of people quickly was for Microsoft to release it as an Open Source project. So, that means I've "given" the code to Microsoft on the basis that they'd make it open source and thereby giving it away to everyone. In practice, it means it's in a Microsoft owned repository but I'm an admin and main contributor.


What is this thing then?

Introducing the Rapid XAML Toolkit.

It's a Visual Studio extension that provides functionality to accelerate XAML development.
It's rare for developers to build the XAML UI for an app before having some sort of data model that the UI will represent and allow interaction with. It might be from a database, web service, or somewhere else but if you've got some code that describes what should be there, why not let the tool create it for you?


Of course, it's more than just a file. It contains suitable XAML that represents the ViewModel, wires up the bindings, and sets the data context. It's not going to be the final XAML you need but it's going to do in two clicks what could otherwise take a few minutes. Given the choice, would you rather have a blank page or something that works and you can just tweak to your needs?

As an example, given a class that looks like this:

    public class OrderDetailsViewModel : ViewModelBase
    {
        public int OrderId { get; private set; }
        public Guid CustomerId{ get; set; }
        public DateTimeOffset OrderDate { get; set; }
        public string OrderNotes { get; set; }
        public decimal OrderTotal { get; }
        public ObservableCollection<OrderLineItem> Items { get; set; }
    }

It could produce this:

    <StackPanel>
        <TextBlock Text="{x:Bind ViewModel.OrderId}" />
        <TextBlock Text="{x:Bind ViewModel.CustomerId}" />
        <DatePicker Date="{x:Bind ViewModel.OrderDate, Mode=TwoWay}" />
        <TextBox Text="{x:Bind ViewModel.OrderNotes, Mode=TwoWay}" />
        <TextBlock Text="{x:Bind ViewModel.OrderTotal}" />
        <ListView ItemsSource="{x:Bind ViewModel.Items}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="OrderLineItem">
                    <StackPanel>
                        <TextBlock Text="{x:Bind OrderLineId}" />
                        <TextBlock Text="{x:Bind ItemId}" />
                        <TextBlock Text="{x:Bind ItemDescription}" />
                        <TextBlock Text="{x:Bind Quantity}" />
                        <TextBlock Text="{x:Bind UnitPrice}" />
                        <TextBlock Text="{x:Bind LineTotal}" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>


How does it know what XAML to create?

The generated XAML is based on the type and name of the property and whether it is read-only. There are some carefully chosen options provided by default but everything is configurable. In the future, it may also be powered by AI too ;)


How does it know where to put the created file?

It's based on conventions but is fully configurable. It even supports having the View and ViewModel in different projects if that's what you prefer.


That all sounds like one feature. Why call it a toolkit?

Because there are plans for much more. XAML generation is just the start, but it enables lots of scenarios and opportunities.

Even today, it doesn't just provide the ability to produce whole files. It also provides the ability to generate XAML without having to create the file. You can generate the XAML for an entire class, an individual property, or a selection of properties. This raises the question of where the XAML will go. We leave that up to you. The generated XAML can either be copied to the clipboard (so you can paste it wherever you wish) or sent to the clipboard (so you can drag it where you want it.)

The final part of setting up the basic association between VM and View is to ensure that the data context for the page is correctly set. If it's not, then it provides the option to do this for you.








Does it do X?

Probably not...yet! There are lots of features planned but if you've got a suggestion, please raise an issue in the GitHub repository.


How does this compare to Windows Template Studio?

Windows Template Studio will help you to scaffold a UWP app. The Rapid XAML Toolkit is a sister project and can help you once you've created the stub of your app, or if you have an existing app. It doesn't have to be a UWP app either. We hope this will be helpful to Xamarin developers too.


Wait, what's this about Xamarin? I thought it was a UWP thing.

Nope, it's a XAML thing!
While there may end up being some elements or features that are UWP only, the intention is that it will be beneficial to any developer who is working with XAML. This means Xamarin.Forms and WPF. (It will work with Silverlight too, but I'm just not providing any default configuration for it.)


Really, WPF?

Yes, WPF too.


Anything else?

Yes, it works with both C# AND VB.Net.


Really, VB.Net?

Yes, because all developers deserve nice things. Plus, we think this will be particularly beneficial to developers converting WinForms and WPF apps to UWP, and we know a lot of them use VB. If they're learning UWP, they shouldn't have to learn C# as well.


Where can people find out more?

GitHub is the place. Go to https://github.com/Microsoft/Rapid-XAML-Toolkit and check out the current features.


p.s. As you'd expect, I'll be sharing more details soon, but, if you're at //build, I can show you more. You'll find me at the Windows Template Studio & Community Toolkit booth.




Thursday, May 03, 2018

Personal mission statement

I've been thinking about creating a personal mission statement. Something that simply and clearly sets a guide for what I (want to) work on.
I've come up with this.

Help people create better software.

I think there are two aspects to this: Education and Tooling.

Education
People can't make better software if they don't know what makes better software or how to create it.
I'll do this by providing resources in the form of books, articles, etc.

Tooling
Creating/providing tooling that can help create better software will make it easier and faster for people to do so.


What do I mean by "better"?

- Easier to learn
- Easier to use
- Easier to support
- Usable by more people
- Fast
- Reliable
- Robust
- Secure
- more ...


Some practicalities
- I can't help everyone.
- I'll focus (at least initially) on areas where I have specific knowledge and opportunities.


Wednesday, April 25, 2018

WinAppDriver a base for testing

I've been doing some automated UI testing using WinAppDriver.

Here's a simple base class I've been using for my tests that takes care of ensuring that the service app is running when the tests start.



If you're writing tests using WinAppDriver and are fed up with tests not running or false negatives when the exe isn't running and listening for requests, then check it out.

The check for it being installed is also useful when you first run on a new machine.

You may need to allow for untrusted PowerShell scripts or have VS running as an admin for everything to work.



Friday, March 23, 2018

UWP vs Web development

I recently heard someone try and make this argument. (They were sucking up to Microsoft at the time.)
If I do web dev I have to learn at least 4 things, but for Windows, I can just learn UWP
Their thinking was that for web development they need to learn:

  • HTML
  • CSS
  • Javascript
  • Some framework (e.g. Angular)
  • Possibly more...

They argued that they could just learn "UWP".
But I think that means several things too:

  • XAML
  • C# (or VB, or C++)
  • An MVVM framework (MVVM Light, Caliburn.Micro, Prism, etc.)
  • The UWP app model and platform-specific APIs
  • possibly more...

I don't think this argument holds up.
The development of any piece of non-trivial software requires the use of multiple complementary technologies, skills, and techniques. If you ever think you can just learn one thing and then you'll be done, you're setting yourself up for disappointment and failure.

There's a similar thing I've heard from other developers and that's:
I don't need to learn Android (or iOS) I can just learn Xamarin.
That's equally flawed and in similar ways.


Friday, March 16, 2018

Did someone really design this ATM experience?

As I put my card in the ATM machine today I noticed a message on the screen that said
Receipts currently unavailable
I've seen it many times before. It means the roll of paper the receipts are printed on has run out. Not a problem, I just want cash.

After inserting my card and entering my PIN number, among the many options were two related to what I wanted:

- Cash with receipt
- Cash with no receipt

Yes, that first option makes no sense based on the message shown at the start. But wait.
I selected the second option and was then asked:
Do you want a receipt for your transaction?
- Yes
- No

I selected "No". I didn't want one and, based on what the machine had said moments ago, I knew it couldn't provide one even if I did want it.

I then selected the amount I wanted to withdraw.

All should have been good but then I was asked, again:
Do you want a receipt for your transaction?
- Yes
- No

Again I selected "No" and finally my money was dispensed.

Part of me was glad to finally get my money.
Part of me was tempted to try that again and see if what would happen if I chose some of the impossible options.
And another part of me was saddened by the process.

Here are my issues with what happened:

  • The software repeatedly provided options for things it had said were unavailable.
  • The software asked the same question multiple times, seemingly disregarding my past answers.
  • The software made the process longer and more complicated than was necessary.


Someone was paid to make this software.
Someone tested and approved this software.
Someone thinks this is a good experience to give to their customers.
Someone thinks that we should trust them with our money inside complex financial systems when they make what should be a simple piece of software unnecessarily complex.


You wouldn't build software that provided an experience like this.
Would you?