Posts about the C# language itself, including use, abuse and features.

Equality of validation

Saturday, August 18 2018 validation csharp

While writing tests for the code presented in the last couple of weeks, I discovered a notable bug caused by an ommission in the code. If you’re a regular reader of this blog, you may have already spotted what was left out.

Read more »

Short-circuiting validation

Saturday, August 11 2018 validation csharp

Following on from last week’s introduction of the plus operator, a friend of mine challenged me to consider an alternative operator for combining validation results: &&

Read more »

Aggregation of validation

Saturday, August 04 2018 validation csharp

We’ve created the basics of our validation library, but we haven’t yet addressed the problem of aggregation. How do we make it easy for our consumers to combine multiple validation results together into one. Ideally, we want this to be so simple that they don’t have to think about it at all.

Read more »

Recovery of validation types

Saturday, July 28 2018 validation csharp

As alluded in the prior post, all of our return types so far have been ValidationResult - but our consumers will need to know whether they have a success or an error in order to make decisions.

Read more »

Basic validation

Saturday, July 21 2018 validation csharp

To recap from last time, we want to create a simple library that allows us to express validation in a straightforward way, allowing us to concentrate on the rules we’re checking, not the boilerplate needed to make it work.

Read more »

Why we need better validation

Saturday, July 07 2018 validation csharp

The state of validation in C# leaves something to be desired. Recently I was writing some code in the same old classic styles and the frustration got to me - surely there must be a better approach that doesn’t involve great lists of strings, the use of exceptions for flow control, and brittle unit tests.

Read more »

A question of struct performance

Saturday, June 30 2018 csharp

A question came up in an online discussion about the relative performance of using a bare primitive type vs wrapping that type into a struct. Wrapping the type is a common technique used to avoid runtime errors, enlisting the compiler to enforce the correct semantics at compile time instead. But, sometimes people worry about the performance cost of doing this.

Read more »

Equality has Symmetry

Saturday, March 17 2018 equality csharp

If we’re going to implement equality correctly, we need to consider the contract we’re implementing - what are the characteristics of a proper implementation of equality? The first characteristic we need to consider is symmetry.

Read more »

Type Miscellany

Sunday, March 05 2017 immutable-types csharp

As we near the end of this series on immutable types (for now, anyway), here’s a grab bag of things that didn’t seem to fit elsewhere.

Read more »

Testing Immutable Types

Saturday, February 25 2017 immutable-types csharp testing

As alluded to previously, having a good suite of unit tests is critical for ensuring these immutable instances do what they should - after all, there’s no point in having a queue or stack that doesn’t behave.

Read more »

Factory Methods

Saturday, February 18 2017 immutable-types csharp

Our stacks and queues don’t exist in isolation - they have to interoperate with standard framework classes and other domain constructs to be useful. For example, it is extremely useful to have some factory methods to make it easier to construct stacks and queues from existing lists and sequences.

Read more »

Queue Concatenation

Saturday, February 11 2017 immutable-types csharp

If you have a whole sequence of items you want to add to an existing IImmutableQueue<T>, it’s pretty simple to write a loop to add them all. We can make this even easier by writing a simple extension method that handles the looping on our behalf.

Read more »

Older posts

Complex Queues  04 Feb 2017
The Problem with the Simple Queue  28 Jan 2017
Enumeration of Queues  21 Jan 2017
Reversing Stacks  14 Jan 2017
Simple Queues  07 Jan 2017
Queues  30 Dec 2016
Stacks Miscellany  22 Dec 2016
Stack Equality  09 Dec 2016
Enumerating Stacks  03 Dec 2016
Stacks  19 Nov 2016
When (not) to use Var  16 Jul 2016
Semantic Types Redux  05 Jun 2016
Semantic Types in C#6  27 May 2016
Property Enhancements for C#  20 Dec 2015
Language Extensions for C#  19 May 2014
When should methods be Static?  09 Oct 2012
Of Method Naming and more  29 Sep 2012
Someone needs an intervention  16 Dec 2011
CallerInfo in C# 5  08 Dec 2011
Regions in C#  16 May 2011
Lambda expressions and Block syntax  15 Apr 2011
Parameter Attributes and more  05 Feb 2011
Elegant.Data  19 Oct 2010
Doing less with LINQ  30 Jun 2010
WCF and IList  28 May 2010
Specialist Classes  22 May 2010
Attack of the Lazy Coder  20 May 2010
A Discovery in Linq: Lookup  11 Feb 2010
Co- and Contra-Variance in .NET 3.5  15 Sep 2009
When to use Var  26 Mar 2009
Struct Weirdness  11 Feb 2009
Contravariance and Covariance at last  29 Oct 2008
Spec#  30 Apr 2008
Lambda Events  22 Mar 2008
No longer the C# we knew  21 Mar 2008
Rare C#  12 May 2007
Generics in .Net  28 Jan 2004