Tuesday, November 27, 2018

This is a test - a big, complex test

Duration: 3:46:04 - 96 Tests Failed - 24 Tests Passed
Before
Duration: 2:27:27 - 30 Tests Passed
After
It's not a fun place to start.
After creating a series of tests (120 in total), only 24 passed and it took 3 hours and 46 minutes to run.

No, these aren't simple unit tests. Something would be very wrong if they were.
These are complex integration, end-to-end system tests.

These tests relate to Windows Template Studio and verifying that apps generated with different frameworks (CodeBehind, MVVMBasic, MVVMLight, Caliburn.Micro, and Prism) all produce the same output.
I already have separate groups of tests which check equivalent apps created in C# and VB.Net produce the same result.
I also have tests which compare functionality and output at a passive, static level but I suspected there was potential value in running the generated apps and checking them too.

When creating templates, the MVVM Basic version is usually created first, so this became the reference version.


Here's what each test does:

For each navigation type and page that can be added to the app:

  • Generate an app with the reference framework, specified nav type, and just the specified page.
  • Generate apps with each of the other frameworks using the same nave type and page.
  • Disable .NET Native compilation for the projects. (So they build much faster--the tests would take much much more time without this.)
  • Build the release version of all the apps (using the created certificate.)
  • Install the temporary certificate created with the app and used to sign it.
  • Install the generated apps (Must be a signed, Release version for this to be possible. --This is the equivalent of what VS does when deploying/running a version for testing.)
  • For each of the other frameworks.
    • Create a new test project.
    • Update the project to have references to the reference app and the comparison app.
    • Run the tests in the test project. They:
      • Launch the ref app.
      • Maximize the app once opened.
      • Take a screenshot.
      • Restore the app size.
      • Close the app.
      • Launch the comparison app.
      • Maximize the app once opened.
      • Take a screenshot.
      • Restore the app size.
      • Close the app.
      • Compare the screenshots (allowing for areas that will be different--like the app name in the title bar--and running on different size screens and system scaling.)
  • If all screenshot images are identical.
    • Uninstall the apps.
    • Remove the certificates.
    • Delete the apps and test projects.
  • If screenshot images are not identical.
    • Create an image highlighting the differences.
    • Leave all artifacts created during testing to help investigate why the test failed.

See, not a simple test.

Originally I had separate tests for each comparison but changed to the above approach to reduce the number of times the reference app needed to be created. The details in the failure message meant that having separate tests didn't help with debugging at all. Also, the ability to run individual tests and customize the reference frameworks meant that I could avoid unnecessary work when verifying specific fixes.

The good news about all this work is that it did find some issues with the generated projects and fixes have been made.

Having known test suites that take more than 5 days to run in their entirety, I have strategies for managing long-running test suites. Running all the tests in this solution takes over 18 hours, but the long-running ones are only run manually before a release and many can are normally run in parallel.

No, we don't run all the tests, all the time.

A notable extra lesson from these new tests was that page layouts behave differently for an app that is opened and then maximized and apps that are opened maximized. Seriously. It's potentially concerning but I have more important things to focus on right now.



Thursday, November 15, 2018

Diversity in tech is about more than gender

It's about a lot of things.
In the context of diversity within tech communities, here are two that I'm not hearing other people talk about: technology discrimination and alcohol.

Do you like my new T-shirts?

It's not about the technology used but what's done with it that counts

If you want to be part of a group of people that are just like you: who have similar experiences, interests, areas of technical focus, and goals, that's okay.
However, I think everyone benefits when a community is open and inviting to people with different backgrounds, interests, skills, and experiences. When there's variety in the room it provides the opportunity for us all to learn new things.

We all benefit when we are exposed to others who are different to us. It makes us better developers and better people.

If you want a community to grow. If you want new people to learn and adopt a technology so it becomes successful that requires that you help new people and make them feel welcome.

You mustn't make fun of people because of the programming language they currently use.
They may have had no say in this. They may be very successful with it and have created many popular, loved, and financially rewarding pieces of software with it. The programming language used to write a piece of software rarely plays a large part in the success or failure of that software. Don't pick on people because they use something that's older than what you use or that you have stopped using.

Do not make fun of people because of the platforms they build tech on.
Again, developers rarely have a say about the platforms they use, particularly in corporate environments. If developers only worked on the latest platforms or used the latest frameworks then the majority of software in the world wouldn't be being maintained or updated. If we want to keep society moving we can't abandon all old software and we can't constantly re-write everything that's in use.

I've seen the numbers. Most developers don't use the latest and greatest technologies or the hottest new language.
If you do, then congratulations. How about sharing your knowledge with others who haven't had that opportunity yet? Help them learn new things. Even if that means you have to help with "older" technologies.


Alcohol and a drinking culture

Not everyone wants to or can drink alcohol. Some people are unable to be around alcohol.
Even if someone who doesn't drink alcohol is in a place where alcohol is served they don't want to be made to feel different or left out.

As a user group organizer, I found people were really positive when we had more than just a small selection of beers to drink. More people were even more positive when I extended the range of soft drinks that were provided. When organizing an evening user group event and providing drinks, I now do one third as a mixture of alcoholic drinks, one third as soft drinks, and one third as fruit juices. Fruit juices were amazingly popular when we first started having them.

When holding evening events in offices or meeting rooms I'd often propose going to a bar afterward. This choice of location was chosen because it was easy and pretty much the only location available. Plus, "it was just what you do." I have the cultural experience where going to a pub to socialize is the norm. However, only a small percentage of people who came to the initial meeting would also come to the pub afterward. There are many reasons for this but I believe the location was one of them. Next time I run an evening event where we can't stay in the meeting venue indefinitely, I'll look harder for alternate locations where we can continue discussions afterward.

I don't drink alcohol. I choose not to based on past experiences and my levels of self-control. Other people don't drink alcohol for other personal or religious reasons.
I'm happy to be in places where alcohol is served and drunk. There are people who are not. Again, this could be for personal, religious, or other reasons. If you host an event involving alcohol it will automatically keep some people away. If an event is about technology, why use something unrelated (alcohol) to keep a large number of potential attendees away.

I've been to a number of events where the presence of alcohol made me (as a non-drinker of alcohol) seem less welcome.

  • I was at a conference party with multiple bars serving alcohol. There was only one serving soft drinks. I discovered this as I went round all the bars asking for soft drinks and it was only the last one I came to that had anything. The options were limited and hidden at the back while multiple alcoholic beverages were on display on the counter. The message I took from the conference was that my needs as an attendee were not important.
  • I was invited to an event where special, custom, themed, cocktails were being served. This was a tech event and the cocktails were free. I asked what non-alcoholic drinks they had but these were very limited and I had to pay (an unusually large amount) for a coke. The message I took from this was that this was an event for people who drank alcohol. Even though I'd been invited they didn't value me as much as other attendees.
  • I once attended a tech event in a bar and the only soft drink they had was coke. I was looked at like there was something wrong with me when I asked if they had any other non-alcoholic drinks. Just drinking cola all night can be unpleasant. Ensure there is more than one non-alcoholic option and don't make people feel uncomfortable if they don't want alcohol.
  • I've known tech events where the social aspect was a bar-crawl. Events that encourage lots of drinking (even if that's just implied by visiting lots of different places that serve alcohol) discourage some from attending. 
  • I've been at invite-only tech events where the social aspect of the event was beer and spirit tasting. Again, this is actively excluding people from something that was supposed to be tech related.
  • I've been to a tech event held in a brewery. A great way to exclude people who can't visit such locations.


I know it's hard to find locations for events. I know it's the norm to do these kinds of events. I know I may seem hypocritical for saying this as I've held events in pubs and bars.
However, if you reward or recognize people in your community with alcohol or events involving alcohol then you make people who don't drink alcohol or actively avoid it less welcome in your community.

If you're a leader or organizer and you want to grow your community (both in numbers and diversity) I hope you'll think about this.

Personally, I'd love to organize and attend more meetups in coffee shops and learn from people who use technologies I don't.


Wednesday, November 14, 2018

Another day another project: MultiLineStringAnalyzer

Today I had a lot of potentially tedious and error-prone work to do regarding changing some long string constants within some unit tests.

The tests (among a few other things) compare multi-line generated strings.

All had been good while it was only running on Windows, but now it needs to run regardless of the line-endings in use. This meant that everywhere there were implicit, multi-line strings, tests were failing.

The solution was to change all the tests so that they worked regardless of the line-endings of the machine they are running on.

To make this easier for me I created a tool.
It's probably easiest to show what it does.


It's a C# analyzer that makes changing multi-line strings to use environment appropriate line-endings much simpler and without the risk of manual error.

Just two clicks and it's all converted for me. And as I did this in 100's of places, even with the time spent creating the analyzer the conversion process was much quicker.

The chances are you'll never need it but if you have to do something like this is future it's here for you.
When I say here, I, of course, mean on GitHub.
Or you could install it as a NuGet package.



Tuesday, November 13, 2018

Announcing: UWP Essentials


I want to help make it easier to get started with UWP development.

In terms of the tools available to help UWP developers, there are two challenges.

1. Knowing what tools are available to help with development.
2. Getting everything available installed.

Visual Studio 2017 version 15.8 introduced new functionality to help with this. It's called Extension Packs and is a way to create an extension that bundles (or packs) together a number of other extensions.

So I made one for UWP developer tools.

Consider it a one-stop shop for setting up your machine for UWP development. You can be new to UWP development or just want an easy way to make sure all the useful tools are installed.

The first version contains these extensions:


I've published this myself, even though I'm not responsible for all the packages, but I'd love for this to be a community-supported resource and so I'm keen to hear if you have suggestions for other extensions that should be included as well.

Even if you don't want to install all the included extensions you can unselect what you don't want when you install.

Select what you want to include as part of the installer process 

You'll need to be using Visual Studio in version 15.8 or above for this to work.

Go get it from within VS or from the marketplace.


If you have suggestions for other tools that should be included raise an issue on GitHub.


Monday, November 12, 2018

Some quick notes on converting String operations to use Span

I was asked on Twitter , regarding String Resource Visualizer, whether "using Span for string operations [will] make it faster?"

My inclination was that potentially it would, but at a cost of code readability and I wasn't sure if it really needed the optimization.

Also, I'd read a bit about Span<T> when it was first announced and it all seemed very complicated and abstract. I assumed that it was more for low-level things and I could happily ignore it.

It nagged me though that the String Resource Visualizer was doing a lot every time the text of the editor window changed in VS. Yes, every time the screen is scrolled or the text changes. That's a LOT! In theory, any perf improvements would be a good thing as they could improve the UI responsiveness of Visual Studio. If someone had a slow or low-powered machine this could be important.

Today I had some time on my hands while installing some updates over my disappointingly slow internet connection. So I did some more research on Span<T>.
It turns out it's not as complicated as I thought so I decided it was worth investigating what, if any, improvement could be made from the change.

Because the actual code has some coupling that doesn't lead to easy benchmarking, I created a version of the important part of the code in a separate, console, app.

I then created another version that used ReadOnlySpan<char> instead of a string as much as possible.

All the code is here.


Cutting to the chase, here are the results of the benchmark test.


Or if the image is hard to see, here are the important numbers

        Method |     Mean |     Error |    StdDev |
-------------- |---------:|----------:|----------:|
   UsingString | 67.65 us | 0.4932 us | 0.4372 us |

 UsingSpanChar | 40.85 us | 0.1412 us | 0.1321 us |


Not using string was about one-third faster, but that's only approx. 27 microseconds.

Proportionally that's a lot but in real terms, not so much.


I'm left torn. 
- Making the code faster could be really important given that it potentially runs on every keystroke.
- It's not a lot of time though and no-one is complaining about performance. Could this be an unnecessary micro-optimization?
- There are other parts of the code when a definite performance improvement could be made by reducing IO. This seems a higher priority.
- Having spent years writing code that does string manipulation, I'm not yet ready to jump into making changes that will affect the readability of the code.


I'm going to wait and reflect on this before deciding what to do next.


Announcing String Resource Visualizer

If, like me, you work with code that contains placeholders (generated static properties) for localized resource strings (from .resx files), a codebase that contains a lot of these can be harder to work with than feels necessary. It can take longer to read as you have to look up what the placeholder represents and it's easy to use the wrong placeholder.

This is the scenario I encountered last week.
It got me wondering.

What if there was an extension that could show the text of the placeholder too?

I looked for one but couldn't find anything. Then I wondered.

Could I make one?

After a couple of hours of experimentation, I had the bones of something working.

I posted a screenshot on Twitter to see what others thought.



Based on the positive response the tweet received, I've put something more formal together.

Announcing String Resource Visualizer
It might not seem obvious but this is the VS image for ViewResources
Much like the screenshot in the tweet, it allows you to see the default text for a string resource above where it's used in your C# code.



The code is on Github and you can download the installer from the VS Marketplace. Got get it now and try it out.


There are a couple of known issues that I hope to address soon but I'm keen to hear any feedback or other suggestions for improvements.