Programming

C# Interfaces: Default Implementations

Posted on

The C# 8.0 announcement included a note on default implementations of interface members. If you’ve been programming for long enough, this might make you a little nervous at first thanks to the hangovers of multiple inheritance. Before you chuck out this idea, though, let’s look at it from a different perspective. I’m going to talk […]

Programming

C# Recursive Patterns: Power If Statements

Posted on

One of the new features in C# 8.0 is Recursive Patterns, or Power If Statements. The easiest way to explain this new feature is to unpack the example from the Building C# 8.0 article. IEnumerable<string> GetEnrollees() { foreach (var p in People) { if (p is Student { Graduated: false, Name: string name }) { […]

Programming

Migrating Existing Tests to ApprovalTests

Posted on

This is a short article to describe how I migrated a bunch of existing verbose tests to ApprovalTests. All of the examples in this article are based on my Shameless Green in C# library, which will be familiar to reader’s of 99 Bottles of OOP. Here are some quick links you might want once you […]

Programming

The for Loop Hangover in foreach Land

Posted on

If you are a curly-braces programmer of a certain vintage, you will have done this a great deal in the past. for (let i = 0; i < shoes.length; i++) { const shoe = shoes[i]; // Your actual code here } This was preferable to referencing the janky shoes[i] within the loop, when “shoe” is […]

Programming

NUnit Exception Occurred While Test Discoverer Was Loading Tests

Posted on

If you are using NUnit 3+ with the handy test adapter that shows the tests in the Visual Studio Test Explorer, you might come across an issue loading the tests: An exception occurred while test discoverer ‘NUnit3TestDiscoverer’ was loading tests. Exception: Could not load file or assembly ‘nunit.engine, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb’ or one of its […]

Programming

Code Organisation and Junk

Posted on

Code organisation feels like hard work at times; but there are some mental tricks you can apply to help break the inertia. This article contains a couple of ideas that will help you get moving when you don’t know where to start. I’m not going to go through the steps you need to take to […]

Programming

ASP.NET MVC Widgets with RenderAction

Posted on

This is a useful pattern that I have successfully employed a couple of times with ASP.NET MVC applications; creating Widgets with RenderAction. The prevalent way to create a page in ASP.NET MVC is to grab a bunch of stuff in the controller and pass it into a view to be rendered. As the application grows, […]

Programming

Signs You Broke the Interface Segregation Principle

Posted on

I have written quite a lot about how to follow SOLID principles, but one thing that can be useful is examples of where a principle is not being followed. What does your code look like when it wants to tell you something? Here are the signs that you broke the Interface Segregation Principle (ISP). Here […]