Highlights from Build 2016

Satya

Even though I have never attended a Microsoft Build conference in person I always learn so much from them.

Every year there are new platforms to try, lots of documentation to read, and many presentations and recoded sessions to watch.

I still have a lot of videos to watch, but here are some of top announcements from Build 2016 which matter to me the most as a developer.

Windows 10 as the best OS for Developers

A number of new features coming to Windows 10 in the “Anniversary” update were shown in the day-one keynote, and then even more features where shown at sessions throughout the conference. Solid improvements to the inking, biometrics, and the Action Center were all well received.

Windows Ink

Many of the features shown help fix minor annoyances in the system. For example, pressing on a live tile showing a preview of a news article can now take you directly to it, and notifications dismissed on the PC or tablet will automatically get dismissed on the phone too.

One of the most exciting new features was the addition of Bash (on Ubuntu) on Windows which is both technically very interesting and extremely useful for many development workflows. The new Ubuntu subsystem will allow any (command-line) Linux application to run natively on Windows. This instantly unlocks a massive amount of tools and utilities for developers, making common scenarios significantly easier from Windows.

Bash on Windows

As a huge fan of command line interfaces I’m going to go into this in more detail in a future article – but essentially Microsoft are positioning Windows to be the ultimate developer platform, no matter what operating systems you use for your solutions.

Azure is growing up with more data centres and services

Microsoft would prefer you use Azure when you deploy your applications though, and the day-two keynote showed that is still serious about the cloud.

Improvements which interested me the most included Azure Functions, Service Fabric, Containers, DocumentDB, and much, much more.

Azure

Azure is the future of Microsoft, and by the numbers they going strong. They’re expanding their datacentres and really betting big on the cloud. This is no surprise to Microsoft watchers, but it’s good to see steady improvements here. Many of which I will use.

Visual Studio keeps getting better

I spend absolutely huge amounts of time in Visual Studio so any improvements here have a very positive effect on my productivity.

Visual Studio 2015 Update 2 was released (with lots of improvements) and an early preview version of Visual Studio vNext was also shown. I’ve tried both and they’re definitely going in the right direction for me.

Visual Studio

I’m especially looking forward to some of the improvements coming in the Visual Studio installation experience moving forward. This should make setting up new development environments much faster, and the side-by-side installations means there’s much less risk when installing previews.

App development for Windows, iOS, Android

The mobile app development story from Microsoft is stronger than it ever has been. This year brings a number of improvements to the Universal Windows Platform (UWP) itself, and a more integrated store experience which now includes the apps on the Xbox One and HoloLens.

The Desktop App Converter lets you wrap up existing Win32 and .NET apps into UWP packages, allowing access to new features like UWP APIs – including Live Tiles. Even though I don’t currently develop any Win32 or .NET applications that I want to put in the store, this is an important step and I’m looking forward to the benefits of this as an app user.

Xamarin

For targeting non-Windows devices, the Xamarin platform is now the obvious choice. After recently purchasing Xamarin (and their amazing talent) they’ve decided to make Xamarin available for no extra charge with Visual Studio. And that includes shipping it with the free Community version. Very cool.

The combination of UWP and Xamarin means I can directly apply my C# and .NET skills to making applications for a wide range of platforms, sharing many code components. It’s really coming together nicely.

.NET and the continued move into Open Source

As well as making Xamarin’s development tools free to Visual Studio users, the folks over at Microsoft also announced their intention to open source the Xamarin SDK (including the runtime, the libraries, and command line tools), and give the governance of it over to the .NET Foundation.

Mono, the cross platform and open source sibling of the full .NET Framework has also been re-licenced to be even more permissive, and given to the .NET Foundation. (To be honest I actually thought this was already the case!)

.NET Core, the future replacement of both the .NET Framework and Mono, also saw steady improvements – my favourite of which was official F# language support:

$ cd hellofs/
$ ls
$ dotnet new --lang f#
Created new F# project in /home/julian/hellofs.
$ # I can now dotnet restore and run this F# app using .NET Core!

The Future of Cortana and Conversation as a Platform

So far everything I have mentioned has been mostly around solid updates to existing platforms, but this year’s Build included a slightly different way of thinking about productivity with the idea of Conversation as a Platform.

Conversation as a Platform

The Microsoft Bot Framework provides templates for creating bots with C# and JavaScript, as well as connectors to simplify their interaction with services like Slack and Skype. When linked with the new Cognitive Services, these bots can understand natural language and perform tasks for the user.

build-cortana

The demonstration of talking to Cortana through Skype was very interesting – where essentially Cortana can act as a broker between the user and other bots on the Internet which can act as experts in their field. I found this very compelling, and something I can see myself using.

As this is as subject that interests me greatly, I’ll be writing more about this over the next week or so.

And everything else…

Of course, there’s no way I could summarise everything I looked at so I have skipped a number of cool announcements ranging from Microsoft Graph to HoloLens.

The hard-working folk over at Channel 9 have videos for many of the events and topics, so be sure to check them out if you’re interested. I’m very thankful that these videos are all made available for everyone to watch, I really enjoy watching them.

Interactive showdown: csi.exe verses fsi.exe

Visual Studio 2015 Update 1 brings with it a nice little utility called C# Interactive which you can access from the View menu, but we’re going to have a look at the command line version which you can run from the Developer Command Prompt for VS2015.

Using this tool you can quickly run C# using a REPL environment – which is a fast and convenient way to explorer APIs, frameworks, and script existing code from .NET assemblies in a non-compiled way.

While this is new to Visual Studio and C#, we have enjoyed this functionality for a long time with F#.

(Technically this has been around for a while, but it’s officially shipping now!)

I decided to take a look at the new csi.exe application, and compare it to how I already use fsi.exe and see if it’s enough to make me switch my default command line tool.

C# Interactive

For me the most important way I’d use C# Interactive is via the command line, so it’s important to know what it’s capable of, even though you may not need to use the advanced features right away.

To find out the current version and get a list of the command line options in C# Interactive, just add the /? switch and read the output:

PS> csi /?
Microsoft (R) Visual C# Interactive Compiler version 1.2.0.51106
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: csi [option] ... [script-file.csx] [script-argument] ...

Options

/help Display this usage message (alternative form: /?)
/i Drop to REPL after executing the specified script.
/r:<file> Reference metadata from the specified assembly file (alternative form: /reference)
/r:<file list> Reference metadata from the specified assembly files (alternative form: /reference)
/lib:<path list> List of directories where to look for libraries specified by #r directive. (alternative forms: /libPath /libPaths)
/u:<namespace> Define global namespace using (alternative forms: /using, /usings, /import, /imports)
@<file> Read response file for more options
-- Indicates that the remaining arguments should not be treated as options.

Form a first look, I can see that csi.exe has all of the command line options I really want in normal use – I especially find /i to be useful – but we’ll come to that shortly.

F# Interactive

F# Interactive has been around for a lot longer, and is built on different technology under the hood – so there are a more options going on here, but we can take a look by providing a similar -? switch:

PS> fsi -?
Microsoft (R) F# Interactive version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

Usage: fsi.exe <options> [script.fsx [<arguments>]]...

Input Files

--use:<file> Use the given file on startup as initial input
--load:<file> #load the given file on startup
--reference:<file> Reference an assembly (Short form: -r)
-- ... Treat remaining arguments as command line arguments, accessed using fsi.CommandLineArgs

Code Generation

--debug[+|-] Emit debug information (Short form: -g)
--debug:{full|pdbonly} Specify debugging type: full, pdbonly. ('full' is the default and enables attaching a debugger to a running program).
--optimize[+|-] Enable optimizations (Short form: -O)
--tailcalls[+|-] Enable or disable tailcalls
--crossoptimize[+|-] Enable or disable cross-module optimizations

Errors and Warnings

--warnaserror[+|-] Report all warnings as errors
--warnaserror[+|-]:<warn;...> Report specific warnings as errors
--warn:<n> Set a warning level (0-5)
--nowarn:<warn;...> Disable specific warning messages
--warnon:<warn;...> Enable specific warnings that may be off by default
--consolecolors[+|-] Output warning and error messages in color

Language

--checked[+|-]Generate overflow checks

--define:<string> Define conditional compilation symbols (Short form: -d)
--mlcompatibility Ignore ML compatibility warnings

Miscellaneous

--nologo Suppress compiler copyright message
--help Display this usage message (Short form: -?)

Advanced

--codepage:<n> Specify the codepage used to read source files
--utf8output Output messages in UTF-8 encoding
--fullpaths Output messages with fully qualified paths
--lib:<dir;...> Specify a directory for the include path which is used to resolve source files and assemblies (Short form: -I)
--noframework Do not reference the default CLI assemblies by default
--exec Exit fsi after loading the files or running the .fsx script given on the command line
--gui[+|-] Execute interactions on a Windows Forms event loop (on by default)
--quiet Suppress fsi writing to stdout
--readline[+|-] Support TAB completion in console (on by default)
--quotations-debug[+|-] Emit debug information in quotations
--shadowcopyreferences[+|-] Prevents references from being locked by the F# Interactive process

As you can see there’s a lot more options for F#, but many of them are not needed for every day use.

Quick Interactive Use

It’s fairly common that I use F# Interactive just to test out how part of the Framework behaves.

In this instance, I’ll use HttpUtility.HtmlEncode method to see see what output I get when one of my emoticons is encoded into HTML-friendly characters.

PS> fsi

Microsoft (R) F# Interactive version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> open System.Web;;
> let encode s = HttpUtility.HtmlEncode(s);;

val encode : s:string -> string

> encode "<(>_<)>";;
val it : string = "&lt;(&gt;_&lt;)&gt;"
>

This is how I’d do it in F# – we could call the HtmlEncode function directly, but creating functions is so easy with F# that we might as well shorten the name to make it nice and easy if we need to run it multiple times.

The function encode actually returns a string rather than printing it to the screen, but F# is setting that output to a special value called it – a special identifier which is used for displaying the value of the last expression on the screen. It’s handy, and you’ll see why.

Alright so here’s my first attempt to do something similar in C# Interactive.

PS> csi
Microsoft (R) Visual C# Interactive Compiler version 1.1.0.51109
Copyright (C) Microsoft Corporation. All rights reserved.

Type "#help" for more information.
> using System.Web;
> HttpUtility.HtmlEncode("<(>_<)>");
(1,1): error CS0103: The name 'HttpUtility' does not exist in the current context
>

Ah. HttpUtility is missing because it hasn’t loaded the clases from the System.Web.dll assembly. I didn’t notice on the first line becuase of the way namespaces work – the namespace exists, but not the class we want. No problem, we just reference it using #r – you reference assemblies this way in F# too!

> #r "System.Web"
> HttpUtility.HtmlEncode("<(>_<)>");
>

This worked and we have access to the static HttpUtility class and the HtmlEncode method – however the output has not been displayed to the screen because C# Interactive doesn’t have that the specal it value F# had.

I didn’t realise this at first but in the absense of the it value F# has, the C# Interactive prompt introduces a slightly different syntax for when you want to see the value.

> HttpUtility.HtmlEncode("<(>_<)>");
> HttpUtility.HtmlEncode("<(>_<)>")
"&lt;(&gt;_&lt;)&gt;"
>

Notice the difference a semicolon makes? This is important, and something I missed when first trying out C# Interactive. Avoiding the semicolon would normally result in invalid C#, but this is a great way to view the output as if you’re typing it into the Immediate Window in Visual Studio.

Let’s also create a function using normal C# syntax so that we don’t have so much typing to do. Notice that I’m going to call this function without the semicolon so that I can see the output.

> string encode(string s) { return HttpUtility.HtmlEncode(s); }
> encode("<(>_<)>")
"&lt;(&gt;_&lt;)&gt;"
>

Loading Scripts

Let’s keep things simple, we’ll take the functions we just created in each langauge, and create a script file so that they can be loaded up when we start an interactive session.

First of all, let’s do it with F#. Here’s the content of encode.fsx:

open System.Web
 
let encode s =
    HttpUtility.HtmlEncode(s)

And then we can run it from the command line using the --use switch. This will drop us into an interactive prompt after the code file has been loaded.

PS> fsi --use:.\encode.fsx

Microsoft (R) F# Interactive version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

>
val encode : s:string -> string

> encode "<(>_<)>";;
val it : string = "&lt;(&gt;_&lt;)&gt;"
> encode "<(^o^)>";;
val it : string = "&lt;(^o^)&gt;"
> encode "<(T_T)>";;
val it : string = "&lt;(T_T)&gt;"
>

Not bad at all. So let’s do the same thing with the C# interactive, using a file called encode.csx:

#r "System.Web"
using System.Web;
 
string encode(string s)
{
    return HttpUtility.HtmlEncode(s);
}

I love that they used a similar extension! And again, we can run the code file and then get an interactive prompt as above using the /i switch.

PS> csi /i .\encode.csx
> encode("<(>_<)>");
&lt;(&gt;_&lt;)&gt;
> encode("<(^o^)>");
&lt;(^o^)&gt;
> encode("<(T_T)>");
&lt;(T_T)&gt;
>

We have the same end result, though like before the actual functions behave slightly differently. C# Interactive gives a cleaner output here, though you can always clean up the F# Interactive prompt a little bit by using the --nologo switch.

Use Inside PowerShell

Because I want to get access to both of these utilities as fast as possible, I have added a few lines to my PowerShell profile which will ease their use.

I’ve mentioned doing this kind of thing before – and I highly that developers using Windows spend a good amount of time learning PowerShell – but here’s a little snippet that may be useful.

$PROGFILES32 = "C:\Program Files (x86)\"
 
# create an alias to the full path of the executable
Set-Alias fsi "$PROGFILES32\Microsoft SDKs\F#\4.0\Framework\v4.0\fsi.exe"
Set-Alias csi "$PROGFILES32\MSBuild\14.0\Bin\amd64\csi.exe"
 
# add helpers which include common switches
function fsu ($fsx) { fsi --nologo --use:$fsx }
function csu ($csx) { csi /i $csx }

Adding this to my profile means I can just run them using fsu encode.fsx or csu encode.csx respectively. Very easy.

Highlights from Build 2015

The Build 2015 conference has just taken place in San Francisco.

Like last year, this has been another huge event for Microsoft, and a big deal for the people who build solutions using their technologies.

There have been way more interesting things happening than I can possibly cover in one article, but I have decided to cover the three most important to me:

.NET, Windows and Azure.

An exciting future for .NET and Open Source

The future of .NET is the continued push to an open source .NET Core, which is at the centre of both the latest ASP.NET runtime and the Universal Windows app platform. In the future, this will expand and include other application types. In my opinion, they’ve picked the right place to start.

Applications running on the CoreCLR can be developed and deployed on cloud and server-based infrastructures running different operating systems including Windows, Linux and OS X. I have been watching the development efforts on GitHub for a while now, and I’ve set it up on my own machines running both Windows and Linux. It sure is a sight to see.

As well as the core runtime itself going open source, other technologies like Roslyn have enabled products that many wouldn’t have guessed would see the light of day. Having an open source compiler platform has enabled Visual Studio Code – a new cross platform text editor with Intellisense – to be built.

I was lucky enough to see Visual Studio Code before it was announced, and it changed the way I thought about collaboration with Mac users instantly. I’ll have more on this new text editor soon.

Visual Studio Code

With the RC of Visual Studio 2015 there have been some big improvements in the languages supported including both the more traditional C# and Visual Basic, and (my personal favourite) F#.

The Visual F# improvements in ‘every day’ activities are dramatic for anyone who has been using the language. This is all thanks to the new open source attitude, and the amazing community around F# who have helped to develop the Visual F# tools on GitHub.

This new world of cross-platform and open source .NET technology is going to enable some amazing scenarios for .NET developers like myself.

Windows 10’s application platform takes shape

The aforementioned Universal Windows app platform is really taking shape now. Gone are the days of very prescriptive (and maybe too forward-looking) design patterns of Windows 8, and in is the ‘do what’s right for your applications‘ model that has been working well for some for a while.

Universal Windows apps scale from the smallest phones and Internet of Things devices up to the large screens of the Xbox One and the Surface Hub. The most ‘universal’ of these apps are built with just one binary which includes a scalable UI. This allows you to even have the ‘desktop’ app experience when used on a landscape 5.7 inch phone, or when plugged into an external screen using an amazing new Continuum for Phones feature.

For app developers there are some interesting (and controversial) new ways for software venders to build for Windows. The biggest of which are the bridges from Android and iOS. These two are extremely important for the phone and work especially well for iOS games which don’t rely too heavily on the operating specific UI elements. Combined with the bridges for ‘classic windows’ apps and websites using Microsoft Edge, the Store should get a lot more apps on this Windows 10 wave of releases.

From a user’s view, Windows 10 has really rounded out, with the latest Insider Preview feeling a lot more polished than any of the previous builds. Seeing HoloLens run standard Windows Universal apps was a big deal too.

I’ll have more thoughts on these in the future as the Insider Preview continues, and more information for HoloLoens is released at E3.

Microsoft <3 Docker and other Azure improvements

Azure, and the Microsoft Cloud in general, continue to amaze me. Microsoft has managed to embrace this new way of building (and selling) software in at breakneck speed. Additional services were added throughout the platform all the way from storage and networking, to analytics and machine learning. Way too many for this article.

Two of the biggest highlights were the ability to run the complete Azure Stack locally, and Azure’s new Data Lake features too, something which Amazon has had a lot of success with.

Microsoft <3 Docker

For me though, the most interesting changes were around Docker support across Windows and Azure. Docker has been on my radar for a while, but I have yet to use it in production. I have plans to do so in the not too distant future.

Remote Desktop to the Cloud

Remote Desktop for Windows Desktop

For the last six months I’ve been using an Windows 8.1 virtual machine running in Microsoft Azure for various day-to-day developer activities. It has ended up being extremely useful to have a full Windows machine that’s accessible from any place and any device.

Azure

The VM I’m using is A2 Standard and running Windows 8.1, set up with my Microsoft account so all my apps are working on it properly – from Windows Store to Office 365.

Most importantly it also provides an always-on development platform for all my applications even when my main PC is being reinstalled with the Windows 10 technical preview builds. I have access to Visual Studio, F# Interactive, Node.js and all my usual scripting tools in PowerShell at any time.

Remote Desktop for Windows Phone

The remote desktop client for Windows Phone is truly brilliant too, with support for a virtual mouse pad enabling me to get access to applications like Visual Studio or Outlook at any time. True it’s a little fiddly, but it’s really powerful.

Azure’s Virtual Machines suite me as I have a number of credits every month, and nowhere at home to keep a server that could be on 24/7. Overall I’m really pleased with the service.

String Hashing in F#

I recently wrote a small program to convert some strings into a ‘unique enough‘ hash which could be used as a short reference.

Whenever I’m trying to come up with an idea of how to handle these kinds of functions, I tend to turn to my favourite language, F#. This allows me to do rapid prototyping in a very functional way.

Below is the prototype version of this hashing program:

open System
open System.Text
open System.Security.Cryptography

let encode (alpha:string, number:int) =

    let b = alpha.Length

    let rec enc (s:string, n:int) =
        match n with
        | x when x <= 0 -> s
        | _ -> enc (s + alpha.[n % b].ToString(), n / b)

    match number with
    | 0 -> alpha.[0].ToString()
    | _ -> enc ("", number)

let md5Int (input:string) =

    let clean (str:string) =
        str.ToLowerInvariant()
           .Trim()

    let computeHash (str:string) =
        let bytes = Encoding.Unicode.GetBytes(str)
        use crypto = new MD5CryptoServiceProvider()
        crypto.ComputeHash(bytes)

    let convert (bytes:byte[]) =
        let i = BitConverter.ToInt32(bytes, 0)
        Math.Abs(i)

    convert (computeHash (clean input))

let hash (input:string) =

    let a = "ABCDFGHJKLMNPQRSTVWXYZ0123456789"
    let i = md5Int input

    encode(a, i)

Once I have this program created, it’s very easy to use in F# Interactive like so:

> hash "Here is a test string!";;
val it : string = "1W2ALLB"
> hash "The hash is much smaller, which is great.";;
val it : string = "5DAF5T"
>