This post is the first in a series - for once I will split a large topic into a few small posts. The series is about covariance and contravariance, together known as variance. Arrays and listsContravariance in interfacesCovariance in interfaces Covariance and contravariance are terms I came across occasionally, and never understood properly. Having put … Continue reading Covariance and contravariance – part 1: Arrays and lists
Category: C#
Usability for programmers
I recently started learning Xamarin. I should say I’ve started learning it again, because the first time I just couldn’t get into it. This time it’s going better, although I’ve still been struck by something that’s surprisingly labour-intensive and so surprisingly annoying. This made me think about the relatively cushy world I normally experience when … Continue reading Usability for programmers
Explaining virtual methods in C# with words and pictures
In this post I will try to explain virtual methods in C#. There are similar concepts in other languages, like C++ and Java, but I can’t vouch that all the details I go into here will apply exactly to any other language. The whole post is quite long, but I want to get to a … Continue reading Explaining virtual methods in C# with words and pictures
Performance optimisation – for machines or people?
I recently watched a video and listened to a podcast that form an interesting pair of opinions about performance. The video is Patterns for high-performance C# and the podcast is SE-Radio Episode 357: Adam Barr on Software Quality. There are two things where the podcast and video have no differences: the system must behave correctly, … Continue reading Performance optimisation – for machines or people?
Unit testing database queries
In this post I will try to describe an approach to unit testing database queries. It happened to be inspired by some testing I was doing of some C# code, but you could apply the same ideas to other languages. Note that if you’re unit testing stored procedures then I recommend using something like tSQLt, … Continue reading Unit testing database queries
Lazy initialisation and threads (in C#)
Lazy initialisation is a way to set up everything needed to initialise something, but put off the initialising until later, usually when the value of the thing-being-initialised is needed for the first time. You might want to use lazy initialisation because something is expensive to initialise, and you might not need it. Or because you … Continue reading Lazy initialisation and threads (in C#)
Documenting ASP.NET REST APIs with Swagger / Swashbuckle
Introduction Swagger is a way to document a REST API, and tools can automate much of this process (but not all of it). At the centre of things is a JSON file that describes the API. You can create this file by hand or use a tool to generate e.g. from the API source code. … Continue reading Documenting ASP.NET REST APIs with Swagger / Swashbuckle
An introduction to Entity Framework
Introduction This is article isn’t a hands-on guide to getting started with Entity Framework (EF). Instead it aims to give you an understanding of what EF is, whether it’s for you, and if so, which of its options apply best to you. In the next article I will do the hands-on stuff, where I walk … Continue reading An introduction to Entity Framework
Named parameters with default values can help unit tests
Introduction I find myself using default values much more in unit tests than in production code. That is, I do it more often, and use more parameters with defaults per method. This isn't because default values are bad, but they are often particularly useful when setting data up for unit tests. It makes the tests … Continue reading Named parameters with default values can help unit tests
Testing a Web API
If you write a Web API (I’m using this to mean any API that you call via HTTP, such as a REST API using the Microsoft Web API framework), the world it’s part of is: It’s likely that while you’re developing, Client machine = Web server machine = Database machine, but this might not be … Continue reading Testing a Web API