February 17, 2017 · netcore roslyn aspnet .net ·

.NET Core Ecosystem - My thoughts

I have been following the .NET Core development and release for a while and excited to see the direction where it is going. I think this should have been the focus some time back, however its still good time with many lessons learned over the years.

Involving the community and opening up the source and accepting contributions was one of the key factors in making .Net Core a great product. Making a .NET Standard was another one, providing an api surface area in various platforms much like the C++ Standard Library. Beautiful. Supporting multi-platforms (Windows, *nix, OSX). Awesome.

Since I have not been living under a rock, I have kept a keen interest in these developments. Over the past year I've also become comfortable with python. Mostly using Django framework to develop web applications and AngularJS and HackerRank. For Python I use PyCharm and Visual Studio Code

I am still interested in scalability and the direction where the Actor model has been going. Concurrency and parallelism both on the client side and server side are my passion, but I have been meddling with the following for a while and hope to create content relating to all of the above.

It is important to also mention that the following are all opensource frameworks with a lot of community involvement.

Roslyn Compiler

During this period I have seen very interesting developments happening in the Rosyln (The C# 7 compiler). My favorite feature being the following:

1) Tuples

Looking at the Tuples one sees the syntactic sugar enabling a resemblance to python than the previous implementation.

C#

(string alpha, string beta) letters = ("a", "b");
var moreLetters = (alpha: "a", beta: "b");
WriteLine(moreLetters.alpha);

Python

(ten, twenty) = (10, 20)
print ten

In the previous versions, you needed to create a new instance of a Tuple data structure and access the items using property names which were not named nicely. i.e. Item1, Item2... Notice that, you are able to access moreLetters.alpha in the example above. You may also have noticed that I did not write Console.WriteLine(...), this is because you are now able to add a using clause which imports the static methods from a class. e.g.

using System;
using System.Collections.Generic;
using static System.Console;

The underlying implementation of the C#7 Tuple is a System.ValueTuple struct which is different from the System.Tuple class we used before. Thus, the new Tuple is a value type rather than reference type as the previous one. As you know there is an internal difference in the way value types and reference types are managed by the compiler.

2) Pattern Matching

If you look at the following C# segment,

        // Use 'case' with pattern expressions
        switch (shape)
        {
            case Circle c:
                WriteLine($"circle with radius {c.Radius}");
                break;
            case Rectangle s when (s.Length == s.Height):
                WriteLine($"{s.Length} x {s.Height} square");
                break;
            case Rectangle r:
                WriteLine($"{r.Length} x {r.Height} rectangle");
                break;
            case null:
                throw new ArgumentNullException(nameof(shape));
            default:
                WriteLine("<unknown shape>");
                break;
        }

Now check this one in Scala. There are some similarities here in that types are are matched sequentially. The great advantage you have in C# 7 is that you are able to declare and use that matched case. You are also able to apply further constraints using when clause after matching, which I think is awesome.

object MatchTest2 extends App {
  def matchTest(x: Any): Any = x match {
    case 1 => "one"
    case "two" => 2
    case y: Int => "scala.Int"
      }
      println(matchTest("two"))
}

I have only given one example using a switch statement, but pattern matching also support is operator and it gives you a neat ability to declare a variable where the value will be assigned if the type is matched.

3) Local Functions

These are basically functions withing functions. You could technically do this before though Action<> or Func<> delegates. I remember when I made a recursive tree traversal algorithm using that approach a few years ago.

I check quite frequently the https://github.com/dotnet/roslyn/blob/master/docs/Language%20Feature%20Status.md link to see the status of the new features. :)

.NET Core

This is the unified, fast, multi-platform, opensource framework that is quickly seeing a lot of participation and adoption by many individuals and companies. There is already a lot of content around this and Scott has written a nice article around this on What .NET developers ought To know to start in 2017

There is a channel on YouTube in which Bertrand Le Roy invites guests to talk about .NET and any other projects related. This is a very nice channel to subscribe to. Some of my favorites episode are the one with Ayende Rahien, Immo Landwerth on NET Standard and JB Evain on Cecil. I never miss an episode.

For more information check http://dot.net or https://www.microsoft.com/net/core/platform

ASP.NET Core

You have to love this.

A lot has been talked about it in various blogs and on the Community Standup - A cool show where Scott, Damien, and sometimes another quest talk about the new developments that have happened, what is happening and what is expected to happen with the ASP.NET Core. There is a section in which the community shoutouts mare made and questions are taken from the community through https://twitter.com/aspnet or https://gitter.im/aspnet/Home It can be accessed here https://live.asp.net/ or better yet, Scott's youtube channel https://www.youtube.com/user/shanselman/videos

So you are interested in developing web applications and you code in C# (maybe F#) and you care about performance, multi-platform, extensibility, testability, simplicity and most of all really cool? Sounds like a commercial, right? No, No, but I'm serious this is fast and there is numbers to prove it.

It offers a unified way of creating MVC, API and WebPages and give you control over the the middleware pipeline. There are many projects centered around it and a lot of community contributions and involvement in this. You will also notice that with the new ecosystem you will be able to use the web tools like (gulp, grunt, npm, bower and others) effectively, from their package repositories. This enables Nuget to focus on your server-side packages and streamline the packages for a specific purpose, but we are also seeing some tooling coming from Nuget as well for CLI.

I have already started a project using this on Visual Studio Code. A multi-tenant SPA application.

I'd recommend that you visit docs.asp.net to get started. I also recommend the Microsoft Virtual Academy as a place to start learning, for free.

Conclusion

I think the direction and the future of this ecosystem is the right one. I cannot wait for the tooling to reach completion and for .NET Standard 2.0, there is already lot of success in this area with templating engine, which will make it simple to create tools for scaffolding applications on CLI and within Visual Studio. It will be interesting to see code shared from all the different web/cloud, mobile, ARM, Desktop on Xamarin, .NET Core, Full .NET.

Its a good time to be a .NET developer.

Some links I often visit

Comments powered by Disqus