.NET R&D Digest (August, 2020)

The summer is over! 😦 But as Monday starts a new week (at least here in Belarus), September starts a Fall, where according to schedules, we can expect many new releases and events, so stay tuned!

This issue (August 2020) might seem smaller than usual but this isn’t entirely true … because 40% of it are pair posts or series! Which gives us not 10 but 21 positions in overall 😊

This issue includes bits of .NET, quantum computing, computer science, Visual Studio and PowerShell.

Have a great read!

Computer Science

  1. Algorithm Design Techniques (by Jon Bentley)
    In day to day development, most of the time, we write an algorithm and only if there are some problems, we optimize it. Modern hardware has a lot of horsepower and forgives many mistakes, so sometimes it may sound, that things like BigO aren’t relevant anymore. In this paper (published in 1984) Jon Bentley describes an algorithmic problem and four different solutions to it. Each solution has different characteristics and uses a different optimization technic (which I recommend you to explore). In the end, Jon provides results of comparing the first algorithm, which has a cubic complexity, run on the Cray-1 supercomputer with the last algorithm, which has a linear complexity, run on a commodity hardware (guess who won). The paper is very easy and fun to read – highly recommended.

Visual Studio

  1. Database Profiling with Visual Studio (by Esteban Herrera)
    Ensuring database queries are efficient and aren’t overused is essential to maintain necessary performance level for many Web application. However, usually such profiling is done using separate tools to capture queries and then backtracking them to code, or by stopping on right breakpoint to see query’s ToString(). In this post Esteban Herrera introduces a new Visual Studio Database Profiler tool (compatible with dotnet trace) that can significantly simplify the process of pin pointing sources of database queries in the exactly the same way we used to profile pin point high CPU usage – through clicking the app and seeing the profiles data.

.NET

  1. DEEP DIVE: HOW IS THE ASP.NET CORE MIDDLEWARE PIPELINE BUILT? (by Steve Gordon)
    Middleware is a core of every ASP.NET Core application, because, essentially, all web applications just process incoming requests (and what could be more important than processing pipeline?). But do you know how processing (middleware) pipeline is build? How ASP.NET Core ensures that all middleware is registered and executed in the right order? In this post Steve Gordon takes deep dive into ASP.NET Core sources and explains (step by step) how middleware pipeline is assembled and executed.
  2. Visualizing endpoints using the DOT language (by Andrew Lock)
    Routing is very flexible and extendable. We can create routes using attributes, custom constraint or even create a “raw” endpoint using middleware. All these routes (no matter how they have been created) model some sort of “map”. This seems natural, so in most cases we just accept it but have ever thought about printing this “map”? In this series (5 posts) Andrew Lock describes how you can visualize this “map” of endpoint routes using GraphvizOnline and DOT language. Besides visualization, Andrew also demonstrates how the same technic can be utilized in unit-tests to ensure correct endpoint registration.
  3. Running Q# compiler and simulation programmatically from a C# application (by Filip W)
    It is quite common to start one application from another. This can be done by calling OS process API to run the executable of we can use some shared components like COM, but what about compiling the app and the executing it right away, without leaving even a file? In this post Filip W demonstrates how you can utilize Roslyn compiler services to compile and execute Q# assembly entirely in memory. While the post focuses on Q# assembly, in general, demonstrated approach can be adapted to any .NET based language.
  4. A Deep Dive into How .NET Builds and Ships (by Matt Mitchell)
    Building a product is easy when … well you have one project.csproj πŸ™‚ However, when number of projects (and solutions) grows, the build complexity also grows, and to be honest it grows exponentially. Now besides running the dotnet build command you have to do a lot of things not only on the build side but also on source control side. All these things start to require a non-trivial effort to ensure everything is done correctly. That is why it is always interesting to read how large products build and ship. In this post Matt Mitchell describes how the whole set of .NET products are build and released and what challenges this process had, currently has and how they are currently solved.
  5. Exploring the code behind IHttpClientFactory in depth and DI scopes in IHttpClientFactory message handlers don’t work like you think they do (by Andrew Lock)
    When IHttpClientFactory was introduced (in .NET Core 2.1 which is BTW almost 2 years old) it become the right way to use HttpClient. Since then, there weren’t many changes in this field, so we all just get used to it. But have you ever looked into how IHttpClientFactory works? In these posts Andrew Lock does exactly that. In the first post Andrew gives a brief overview of IHttpClientFactory purpose and describes how it manages to create a chain of HttpMessageHandlers. In the second post he pays and attention on how dependency injection behaves inside HttpMessageHandlers pipeline and how this potentially can affect your code. Both posts are very detailed with code snippets and diagrams. Besides that they both contain a link to an interesting series about IHttpClientFactory by Steve Gordon which I recommend for reading.
  6. IDisposable: What Your Mother Never Told You About Resource Deallocation (by Stephen Cleary)
    The IDisposable interface was introduced in the early versions of .NET as a way to deterministically deallocate resources. Since then, it became an essential part of .NET and started to be used not only for resource deallocation but also for object scoping and termination. In this quite old (but still relevant post) Stephen Cleary walks through the problems of IDisposable pattern, absence of runtime support and pitfalls. Then, and this is very cool, Stephen provides multiple examples of how following Disposable Design Principle implement IDisposable objects which wrap an unmanaged resource, objects which have other IDisposables as fields.

Quantum computing

  1. Intro to quantum computing with Q# (by Filip W)
    Quantum computing is closer than it might seem. Yeah, right now you hardly can “touch” it if you aren’t a scientist, but you already can play with simulation and, to be honest, many huge providers are expected to provide quantum service in the nearest future. So, it could be the time to get started, but wait is quantum mechanics is something bizarre and hard to understand? Well, yes, it is, but as usual theory is much harder than practice. In this truly amazing series Filip W does a step by step introduction into basics of quantum computing using Q#. Beside code samples all posts contain theoretical background, history, quotes and … they are very well done and very interesting to read. However, beware! These posts require basics of linear algebra πŸ™‚ In addition to these posts I also recommend you to read a post about standalone Q# console applications, also authored by Filip.

PowerShell

  1. Native Commands in PowerShell – A New Approach (Part 1) and Native Commands in PowerShell – A New Approach (Part 2) (by Jim Truher)
    As any shell can execute native commands (i.e. external applications) as well as PowerShell cmdlets. The major difference between these two however is PowerShell cmdlets could return objects, allowing you to construct processing pipelines and do all fancy things we do with object, while output of native commands is as best a JSON or XML. Wouldn’t it be great to have a PowerShell interface, with parameter completion and output in form of object, to these native commands? I think it would be. In these posts Jim Truher analyzes a possible solutions to this problem (with theirs advantages and disadvantages) and demonstrated how you can utilize native command --help to autogenerate wrappers for its commands. Don’t forget to check the resulting PowerShell module that wraps some of kubectl commands.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s