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 […]

Categories
Programming

JQuery and TypeScript – We Have a Big Problem With jquery.d.ts

This is a call to all my TypeScript connections. This is a call to all. We have a big problem with the official Definitely Typed definition for jQuery. The most fundamental definition for the JQuery interface is incorrect, as you can see in the snippet from jquery.d.ts below. We can fix it, but not without […]

Categories
Programming

CSS Clamp: The Goldilocks of CSS Math Functions

There is a problem I have wrestled with a couple of times, which was frustrating to solve… but can now be easily solved using clamp, which is currently in an Editors Draft of the CSS Values and Units Module Level 4 specification. It is sat alongside similar mathmatical CSS nuggets, such as min and max […]

Categories
Programming

Entity Type IdentityUserLogin Requires a Primary Key

You will usually come across this problem in .net Core Entity Framework when you first override the OnModelCreating method in your DbContext. The entity type ‘IdentityUserLogin‘ requires a primary key to be defined. If you intended to use a keyless entity type call ‘HasNoKey()’. If you check your DbContext class, you’ll see that when you […]

Categories
Programming

Run Multiple PowerShell Scripts from a Master PowerShell Script

Having put together some individual scripts that ripped data out of an Excel spreadsheet, I decided to co-ordinate them with a master PowerShell script that would contain my variables and call out to neat little scripts to do work. PowerShell gets tricky to read when it gets big, so I prefer to have a couple […]