Wednesday, November 14, 2018

Another day another project: MultiLineStingAnalyzer

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.





Thursday, June 14, 2018

Revisiting the takeaways from WWDC 2018

I was reviewing the announcements from WWDC and thought that as my takeaways are likely to be different from those of other developers (and that I've seen them share) I'd thought I'd call out what I think is important.


  • Support the devices that the people using your apps have. What people use is more important than supporting the latest devices.
  • Shared experiences are important for people (group facetime) and the adoption of new technologies. (AR games)
  • Integration with the platform/OS (such as SIRI Shortcuts) helps people integrate the services and functionalities your app provides with the how people use their devices.
  • Platforms change, evolve and may not be around as long as your app. (end of OpenGL)  While using no 3rd party tools isn't an option, it's important to be aware of the wider ecosystems and changes around the tools and utilities you use so that if they go away or become deprecated in favor of a new alternative you won't be caught by surprise.
  • People are mobile, not just devices. People even move more than some (phone) devices. Your app experiences may be more useful if they exist on more than a single device type. That may mean using the same app (or an emulated version) or a customized version of it. 
  • Watch what is new and popular in competing apps/platforms and, if appropriate, replicate that functionality. (In Windows Dark Mode has been VERY popular with some people. It only makes sense for that to come to MacOS too.)