Book Club 11/2023: New .NET, New C#
22 November 2023 4 Minutes History DotnetThe release of .NET 8 brings a lot of features I'm excited for!
This is a post in my Book Club Series.
My book club is a montly topical, curated list of things I've been reading, watching, or sometimes writing sent out via my email newsletter.
If you'd like to follow along with my book club, please subscribe; I won't email you more than once a month.
I'm looking forward to turkey day tomorrow gobble gobble! This year I'm thankful that I work in ecommerce so I get to have a peaceful extended weekend because nobody visits ecommerce sites on Thanksgiving weekend. At least that's what they told me in the interview before they hired me. Insert joke about how it's better to be working in ecommerce than at OpenAI this weekend regardless...
Anyway, last week we got the new release of .NET, which brings langauge and tooling updates across the board, so I want to focus on some of those fun things.
First, Blazor has taken the third (or is it fourth now) of the 1,000 steps it needs to take to become a viable platform for SAAS, with hybrid client/server rendering. I don't have a lot to say there, but I use Blazor for a number of personal projects when I need to quickly draw up a UI to look into some .NET backend scenario or another.
Since Microsoft started down the path of .NET Core, the whole ecosystem has been embracing OSS and free software in a way that's completely rewritten the whole modus operandi of Microsoft under Nadella. Indeed, it seems like at this point in time, you can use .NET without a single worry about vendor lock-in. Well, Microsoft is here to save you from that horrible wasteland of unrestricted freedom with .NET Aspire. Nevermind that you probably don't need a distributed system, and even if you did you almost certainly don't need microservices, they have cloud computes to sell you! Aspire makes it easy to avoid footgunning yourself as you begin your next project distributed from the start by skipping you right to the step where you blow your foot off with a bazooka - all hail the mighty Azure! Or, you know, if like 99.99% of all apps out there you'd be fine with it deployed in a Docker container with a couple of related services, you could just use Railway. Note that I'm definitely queuing up an article on using Aspire with Railway despite my skepticism that Aspire is a good idea.
C# hasn't gotten too many updates, but we have two syntactical updates that are essential and should have been included much earlier: collection expressions and primary constructors for classes.
Collection expressions, or perhaps "enumerable literals", should have been a part of the language from the start, and you should convert all of your code over to using these.
var list = [1, 2, 3, 4, 5];
Records have had primary constructors since they were introduced, and I think that was largely related to the desire to have tuple interop (is interop the right word here?), but now classes have them too except quite different. The parameters in a primary constructor for a class are, more logically than records, private members of that class, significantly reducing the amount of boilerplate if you're still using dependency injection. It's been how many years since Scala came out, but now we can be one of the cool kids on the block too! Right?
Anyway, I'll just leave you with a few talks from the .NET conference with some of the other tidbits that should be used in .NET going forward:
- Improving your application telemetry using .NET 8 and Open Telemetry
- Tiny, fast ASP.NET Core APIs with native AOT
- From IL Weaving to Source Generators, the Realm story
- All About C# Source Generators
And then a couple of talks from the lead designers of C# and F# regarding the history and direction of each language: