Categories
Programming

C# 9 Covariant Return Types

Just a quick note on a neat feature in C# 9 that will allow sub-classes to return a covariant return type… what?! Okay, it allows you to return a more specific, or narrower type. For example, we used to have to return the same type… // parent class… public virtual Literature GetLiterature(…) { return new […]

Categories
Programming Windows

Turn an Old Phone into a Programmable Keyboard

It seems like everyone has a high-quality, expensive, programmable deck on their desk these days. Elgato’s Stream Deck, with it’s glowing LCD buttons, comes in flavours that cost between £100 and £200 (depending on how many buttons you want). It’s beautiful bit of kit that glows its way into the hearts of tech geeks everywhere. […]

Categories
Programming

C# 9 Non-Null Parameters

This neat C# 9 feature can be summed up in a tiny snippet of code. You know that code analysis warning that tells you that the argument passed might be null… wouldn’t it be nice if you could refuse to accept null? Well, you can. This is the before… public Book(string firstName, string lastName) And […]

Categories
Programming

C# 9 Record Types

Update! Since this article was published, it is almost certain that the keyword for record types will actually be record not data as it was in this early preview. We have taken a quick look at C# 9 Initializers and Immutability and C# 9 Non-Destructive Mutation. Let’s now look at the full transformation from an […]

Categories
Programming

C# 9 Non-Destructive Mutation

There are some phrases in programming that feel like they belong in a superhero movie. Non-destructive mutation is just such as phrase. It refers to a concept in functional programming that means when you want to change the state of an object, you create a copy with the change – rather than changing the original. […]

Categories
Programming

C# 9 Initializers and Immutability

There is currently a compromise in C# that means you can enable object initialization with getters and setters, or you can prevent external code mutating state by hiding the setter… but not both. C# 9 gives us both with the init keyword. Let’s look at before… public class Book { public string Author { get; […]

Categories
Programming

C# 9 Simplified Console Apps

At Microsoft Build 2020, an interesting new “see less boilerplate” feature from C# 9 was demonstrated. It removes all the code to create the class and static Main method, letting you just start typing your code. It makes your code way-less-nested (okay, two levels), but doesn’t miss any of your usual features. For example, args […]

Categories
Programming Windows

A Glance at PowerToys and WinGet

PowerToys and WinGet are exciting previews for Windows Users. If you are a civilian, you’ll be getting these in general release soon, but for technical folks might want to try things out early. Or now! PowerToys PowerToys has been in preview for a while. You’ll install it when someone shows off FancyZones, which gives you […]

Categories
Programming

How to Drop a SQL Server Constraint When You Don’t Know its Name

If you are looking after a database that has been haphazardly maintained in the past, you might come across inconsistent naming of things such as constraints. When you come to delete the existing one, it might be tricky if it doesn’t have the same name across environments. That’s when you need to do a lookup […]

Categories
Programming

Naming TypeScript Custom Type Guards

This is a super quick one. Be super-careful about how you name your custom type guards to stop consumers falling into a trap. Basically, the name you give a custom type guard and the return type you specify form a kind of promise that you have to be able to keep. Take this example: function […]