The .NET Stacks #59: 🎇 When your Copilot is mostly right
Tags: csharp, dotnet, azure
Published: 2021-08-01 21:28:18

---
title: The .NET Stacks #59: 🎇 When your Copilot is mostly right
published: true
date: 2021-08-01 15:53:00 UTC
tags: csharp, dotnet, azure
canonical_url: https://www.daveabrock.com/2021/08/01/dotnet-stacks-59/
---

Welcome to another week, all. I hope your Monday is off to a good start.

If you follow me on Twitter, you may have heard I [got attacked by six bees last week](https://twitter.com/daveabrock/status/1418027622148321282). I'm fine but appreciate some of you reaching out with comments about whether I'm still "buzzing around somewhere" or "minding my own beeswax" or "ooh, that stings" or even sending memes of a guy with a beard made of bees.

Here's what ~~hive~~ I've got for you this week:

- **One big thing**: Thoughts on GitHub Copilot
- **The little things**: A new source generator for JSON serialization, F# getting some love
- Last week in the .NET world

* * *

## One big thing: Thoughts on GitHub Copilot

Have you caught all the buzz about [GitHub Copilot](https://copilot.github.com/)? It's been out in private preview for about a month and I've been checking it out. Marketed by GitHub as "your AI pair programmer," it provides predictions for your code—either as a single line or even an entire function. It's based on GPT-3, a "[deep-learning model that uses deep learning to produce human like text](https://en.wikipedia.org/wiki/GPT-3)."

To [quote Colin Ebehardt](https://blog.scottlogic.com/2021/07/03/github-copilot-first-thoughts.html):

> Copilot is based on Codex, a new model which is a derivative of GPT3, which has been trained on vast quantities of open source code from GitHub. It is integrated directly with VSCode in order to generate suggestions based on a combination of the current context (i.e. your code), and the ‘knowledge’ it has acquired during the training process.

There's a ton of examples online from amazed developers. For example, you can enter a comment like `// Call GitHub API` and Copilot will create a function that calls the GitHub API for you. Of course, this led to some snarky comments about AI taking our jobs. If you're concerned about that, I'd ask you to look at some of the code Copilot spits out. It isn't perfect, but it learns from you ... and does an OK job. To quote philosopher Brian Fantana: "[60% of the time, it works every time](https://www.youtube.com/watch?v=pjvQFtlNQ-M&t=2s)."

Copilot has massive potential to improve developer workflow and efficiency. For example, how many times do you have to ask Google how to do something you haven't done in a while? Let's say you haven't called `HttpClient` in a while, or you want to read from a CSV file. You search how to do it, find official docs or Stack Overflow, and go back to your editor and do your best. What if you can cut out all that manual work and generate that code in a few keystrokes? You can focus on the problem you're solving and not on "how do I" tasks. As a smart and experienced developer, you'll know that you'll need to understand the code and tweak it as needed. I do worry about those who won't. It's been easy to blindly introduce code since the invention of the Internet, of course, but doing it from your editor cranks it up a few notches.

From Matthew MacDonald's [excellent piece on Copilot](https://medium.com/young-coder/github-copilot-fatally-flawed-or-the-future-of-software-development-390c30afbc97):

> As long as you need to spend effort reviewing every piece of suggested code, and as long as there is no way to separate a rock-solid implementation from something fuzzier and riskier, the value of Copilot drops dramatically. Not only will it save less time, but it risks introducing elementary mistakes that a less experienced programmer might accept, like using float for a currency variable.

This offering—which will eventually be sold by Microsoft—spends a lot of the reputational capital Microsoft has been building with developers since they started embracing open-source software. While it fits with Microsoft's mission to own the developer experience—from GitHub and NPM to Azure and VS Code, just to name a few—I've seen some Microsoft skeptics viewing this as the company cashing in on the goodwill with the community. While you can't be shocked to see a company mining its free service's public data for eventual profit, there are quite a few licensing and legal challenges that need further clarification (saying "the code belongs to you" in its FAQs might not get by a company's legal department).

Even so, I think Copilot will eventually turn into a powerful tool that can help to automate the painful parts of programming.

* * *

## The little things: A new source generator for JSON serialization, F# getting some love

While it's easy to highlight the new .NET stuff like hot reload and AOT compilation, it's just as important to write about the stuff we do every day: like serializing and deserializing JSON. Is it exciting? No. It is fun? Also no. It's something we do all the time, though—so [it was nice to see Microsoft roll out a new `System.Text.Json` source generator](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/).

We've [talked about source generators before](https://www.daveabrock.com/2020/09/05/dotnet-stacks-15/), but a refresher: its code that runs during compilation and can produce additional files that are compiled together with the rest of your code. It’s a compilation step that generates code _for you_ based on your code. It [creates a lot of possibilities](https://github.com/amis92/csharp-source-generators). This provides an alternative for expensive reflection code, which traditionally leads to slow startup and memory issues.

This new source generator works with `JsonSerializer` (and does not break existing implementations, don't worry). From the [post on the topic](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/):

> The approach the JSON source generator takes to provide these benefits is to move the runtime inspection of JSON-serializable types to compile-time, where it generates a static model to access data on the types, optimized serialization logic using `Utf8JsonWriter` directly, or both.

In the end, moving much of this from runtime to compile-time will help with throughput, memory, and assembly trimming capabilities. The trimming is a big one. The generator can shed a lot of unused code and dependencies.

I think the post does a good job of outlining the capabilities and the [rationale for introducing yet another set of APIs](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/#versioning).

* * *

It's been nice to see F# getting some love lately. Microsoft's latest .NET Conf will be _Focus on F#_, [which will take place on Thursday](https://focus.dotnetconf.net/). Last week, the .NET Docs Show [held an F# AMA](https://www.youtube.com/watch?v=gLSUpH6fonY) and Microsoft [introduced its first F# Learn modules](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/new-learn-modules-write-your-first-code-in-f-write-your-first-f/ba-p/2569795). Even if you're a C# lifer, it's hard to argue against the impact of functional languages such as F#. As C# has spent the last few major releases introducing constructs like pattern matching, records, and features that focus on immutability, these are features languages like F# have enjoyed for years.

As for _Focus on F#_, there's [a lot of nice stuff on the agenda](https://focus.dotnetconf.net/agenda). I'm looking forward to seeing F# creator Don Syme teaching Python creator Guido van Rossum F# from scratch. For more information on F# and its context within the C# ecosystem, I recommend brushing up on my interviews last year with [Isaac Abraham](https://www.daveabrock.com/2020/09/19/dev-discussions-isaac-abraham/) and [Phillip Carter](https://www.daveabrock.com/2020/09/26/dev-discussions-phillip-carter/).

* * *

## 🌎 Last week in the .NET world

### 🔥 The Top 3

- Matthew MacDonald asks: [is GitHub Copilot fatally flawed or the future of software development?](https://medium.com/young-coder/github-copilot-fatally-flawed-or-the-future-of-software-development-390c30afbc97)
- Dave Brock [works with Blazor Error Boundaries](https://www.telerik.com/blogs/work-unhandled-exceptions-gracefully-blazor-server-dotnet-6-error-boundaries).
- Andrew Lock [continues his deep dive on StringBuilder](https://andrewlock.net/a-deep-dive-on-stringbuilder-part-2-appending-strings-built-in-types-and-lists/).

### 📢 Announcements

- The Azure SDK team [recaps their July release](https://devblogs.microsoft.com/azure-sdk/azure-sdk-release-july-2021).
- James Montemagno [introduces .NET MAUI Essentials](https://devblogs.microsoft.com/xamarin/xamarin-essentials-1-7-and-introducing-net-maui-essentials).
- JetBrains has released [ReSharper 2021.1.5 and Rider 2021.1.5](https://blog.jetbrains.com/dotnet/2021/07/22/resharper-rider-2021-1-5/).
- The Azure Portal team [provides their June update](https://techcommunity.microsoft.com/t5/azure-portal/azure-portal-june-2021-update).
- Layomi Akinrinade [introduces the new `System.Text.Json` source generator](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/).

### 📅 Community and events

- JetBrains releases [_The State of Developer Ecosystem 2021_](https://blog.jetbrains.com/blog/2021/07/16/the-state-of-developer-ecosystem-2021/).
- Microsoft now has [a private preview for Visual Studio 2022 for Mac](https://devblogs.microsoft.com/visualstudio/join-the-visual-studio-2022-for-mac-private-preview).
- Microsoft has rolled out [some Learn modules on F#](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/new-learn-modules-write-your-first-code-in-f-write-your-first-f/ba-p/2569795).
- The .NET Docs Show [hosts an F# AMA](https://www.youtube.com/watch?v=gLSUpH6fonY).
- Three community standups this week: Desktop [provides updates](https://www.youtube.com/watch?v=38pVA5iXDeE), Machine Learning [holds office hours](https://www.youtube.com/watch?v=sYMdHMlHS4I), and ASP.NET [continues its architecture discussions](https://www.youtube.com/watch?v=Eq0Jvhk0o1Y).
- Reminder: [Focus on F# is on July 29](https://focus.dotnetconf.net/).

### 🌎 Web development

- Khalid Abuhakmeh [works with Blazor and canceling async calls with CancellationTokenSource](https://khalidabuhakmeh.com/blazor-and-cancelling-asynchronous-calls-with-cancellationtokensource), and [gets started with ASP.NET Core and gRPC](https://blog.jetbrains.com/dotnet/2021/07/19/getting-started-with-asp-net-core-and-grpc/).
- Damien Bowden [uses an ASP.NET Core IHostedService to run Azure Service Bus subscriptions and consumers](https://damienbod.com/2021/07/20/using-an-asp-net-core-ihostedservice-to-run-azure-service-bus-subscriptions-and-consumers/).
- Tomasz Pęczek [compares async streamed JSON vs NDJSON in .NET 6](https://www.tpeczek.com/2021/07/aspnet-core-6-and-iasyncenumerable.html).
- Marinko Spasojevic [uses app roles with Azure AD and Blazor WebAssembly hosted apps](https://code-maze.com/using-app-roles-with-azure-active-directory-and-blazor-webassembly-hosted-apps/).
- Hassan Habib [works with OData in ASP.NET Core 6](https://devblogs.microsoft.com/odata/up-running-w-odata-in-asp-net-6).
- Nikhil Mohan [advocates for gRPC](https://www.cncf.io/blog/2021/07/19/think-grpc-when-you-are-architecting-modern-microservices/).
- Mike Brind [works on CSS isolation for Razor Pages](https://www.mikesdotnetting.com/article/355/css-isolation-in-razor-pages).
- Jon Hilton [uses Refit with Blazor](https://jonhilton.net/blazor-refit/).
- Bruno Sonnino [transforms an ASP.NET Core MVC app into a PWA](https://blogs.msmvps.com/bsonnino/2021/07/17/transforming-your-asp-net-core-mvc-app-into-a-pwa/).

### 🥅 The .NET platform

Mike Hadlow [creates an Microsoft.Extensions.DependencyInjection object graph writer](https://mikehadlow.com/posts/service-collection-object-graph-writer/).

### ⛅ The cloud

- Thomas Maurer [writes about getting started with Azure Arc](https://www.youtube.com/watch?v=4su7dW8603Q).
- Matias Quaranta [uses Cosmos DB as an ASP.NET session state and caching provider](https://devblogs.microsoft.com/cosmosdb/asp-net-session-state-cache-provider).

### 📔 Languages

- Anthony Giretti [writes about constant interpolated strings in C# 10](https://anthonygiretti.com/2021/07/22/introducing-c-10-constant-interpolated-strings/), [uses C# 10 to mix declarations and expressions in deconstruction](https://anthonygiretti.com/2021/07/23/introducing-c-10-mix-declarations-and-expressions-in-a-deconstruction/), and [seals overridden ToString() method on records](https://anthonygiretti.com/2021/07/19/introducing-c-10-seal-overriden-tostring-method-on-records/).
- Chris Noring [writes about getting started with F#](https://dev.to/azure/write-your-first-code-in-f-36gl).

### 🔧 Tools

- Sayed Hashimi [designs Web Forms apps with Web Live Preview in Visual Studio 2022](https://devblogs.microsoft.com/visualstudio/design-your-web-forms-apps-with-web-live-preview-in-visual-studio-2022).
- Gergely Sinka [uses Elasticsearch for .NET](https://developer.okta.com/blog/2021/07/16/dotnet-elastisearch).
- Ivan Porta [explores Azure Pipelines YAML templates](https://www.c-sharpcorner.com/article/azure-pipelines-yaml-templates/).
- Charris Herrera [writes about the top Visual Studio profiling tools](https://stackify.com/top-visual-studio-profiling-tools/).
- Niels Swimberghe [proxies phone numbers with Twilio Programmable Voice and Twilio Functions](https://www.twilio.com/blog/protect-phone-number-proxying-twilio-phone-numbers-twilio-voice-twilio-functions).

### 📱 Xamarin

- Dotnetsafer recaps [some new MAUI features](https://dev.to/dotnetsafer/top-5-net-maui-new-features-1mlb).
- Giorgi Dalakishvili [works on Xamarin Forms auth with PKCE](https://developer.okta.com/blog/2021/07/21/xamarin-forms-pkce-sdk).

### 🏗 Design, testing, and best practices

- Over at _martinfowler.com_, [they write about patterns of legacy displacement](https://martinfowler.com/articles/patterns-legacy-displacement/) and [a discussion about extracting product lines](https://martinfowler.com/articles/patterns-legacy-displacement/extract-product-lines.html).
- Patrick Smacchia [writes about best practices for code reviews](https://blog.ndepend.com/what-is-code-review-guidelines-best-practices/).
- Peter Vogel [writes about the 4 truths of testing](https://www.telerik.com/blogs/how-to-maximize-testing-4-truths).
- Davide Bellone [has another clean coding tip](https://www.code4it.dev/cleancodetips/03-use-pronounceable-names).
- Swizec Teller [writes about reading _Software Engineering at Google_](https://swizec.com/blog/what-i-learned-from-software-engineering-at-google/).
- Jimmy Bogard [continues writing about domain-driven refactoring](https://jimmybogard.com/domain-driven-refactoring-long-methods/).
- Richard Lander [hosts a discussion about skills and learning](https://devblogs.microsoft.com/dotnet/conversation-about-skills-and-learning).

### 🎤 Podcasts

- The 6-Figure Developer podcast [talks about Comet and .NET MAUI with James Clancey](https://6figuredev.com/podcast/episode-204-comet-and-net-maui-with-james-clancey/).
- The Coding Blocks podcast [talks about GitHub Copilot](https://www.codingblocks.net/podcast/what-is-github-copilot/).
- The Working Code podcast asks: [what comes after senior developer?](https://www.bennadel.com/blog/4081-working-code-podcast-episode-032-what-comes-after-senior-developer.htm)
- The AWS Developers Podcast [talks about productive dev environments](https://soundcloud.com/awsdevelopers/episode-006-cloud-9-and-productive-dev-environments-with-richard-h-boyd).
- The Azure Podcast [talks to Daria Grigoriu about Azure Static Web Apps](http://azpodcast.azurewebsites.net/post/Episode-386-Static-Web-Apps).
- Coding After Work [talks to Egil Hansen about bUnit and TDD](http://codingafterwork.com/2021/07/18/episode-59-bunit-tdd-and-sci-fi-with-egil-hansen/).

### 🎥 Videos

- Learn Live [works with Microsoft Identity](https://channel9.msdn.com/Shows/Learn-Live/Work-with-users-groups-and-roles-in-custom-apps-and-APIs).
- The On .NET Show talks about [exhaustive case guards in C#](https://channel9.msdn.com/Shows/On-NET/C-Language-Highlights-Exhaustive-case-guards) and [functional-first programming](https://www.youtube.com/watch?v=EUyXU2NJGGk).