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

Queue Testing

Saturday, December 08 2018 priority-queues csharp

It’s vital that our priority queue returns items in the correct order, so we should write some unit tests to ensure that items are returned in the order desired. Fortunately, we can test this fairly easy using property tests.

Read more »

Creating Branching Nodes

Saturday, December 01 2018 priority-queues csharp

For a queue exceeding two items, our existing implementations are insufficient. We need another - a BranchingImmutablePriorityQueue<T>. Each of these nodes will combine two existing sub-queues with a head item to form a tree structure.

Read more »

Two Dual Item Queues

Saturday, November 24 2018 priority-queues csharp

Once we have a priority queue containing a single item, how do we handle enqueuing the next item onto the queue? The answer, of course, is buried in the code from from last time: we introduce the DualItemImmutablePriorityQueue<T>.

Read more »

Simple Queues

Saturday, November 17 2018 priority-queues csharp

As we did with our original immutable queue, we’ll define dedicated implementations of IImmutablePriorityQueue<T> for handling empty and single item queues.

Read more »

Enqueuing Values

Saturday, November 10 2018 priority-queues csharp

After exploring last time how to remove an item from a queue, let’s look at the slightly more complex case of adding items.

Read more »

Dequeuing Values

Saturday, November 03 2018 priority-queues csharp

Before we can start on the actual implementation of our immutable priority queue, we need to understand the algorithms we’re going to use. There are two different scenarios to consider - when we enqueue something onto the queue, and when we dequeue the head.

Read more »

Designing the External API

Saturday, October 27 2018 priority-queues csharp

As we did previously with our regular immutable queue, we should start by considering the design of our external interface - our API. How do we want our users to create and interact with our priority queue?

Read more »

Introducing the Priority Queue

Saturday, October 20 2018 priority-queues csharp

Recently, while working on a personal project, I needed a priority queue. Instead of slamming all of the items into a sorted list and making do, I decided to do the job properly and write a proper abstraction. To keep things interesting, it was an immutable implementation.

Read more »

A better approach to reflection

Saturday, October 13 2018 csharp

One of the recurring themes on this blog is the idea of making the computer work harder, not the user or the developer. I discovered recently that there was an easier and faster reflection technique than the one I was using - the technique that I’d been using for most of a decade!

Read more »

Avoiding Magic Strings

Saturday, October 06 2018 validation csharp

Building on the infrastructure defined last time, let’s look at how we can avoid the use of magic strings when working with metadata.

Read more »

Capturing Validation Metadata

Saturday, September 29 2018 validation csharp

In the last post we showed an api for how we can inject additional metadata into our validation results. The implementation is relatively straightforward - but there are a few moving parts that need to mesh together appropriately.

Read more »

Modelling Validation Metadata

Saturday, September 22 2018 validation csharp

Given our requirement of supporting arbitrary metadata on our validation results, how should we modify the semantic types we’ve already created?

Read more »

Validation Metadata

Saturday, September 15 2018 validation csharp

It’s a common requirement for validation messages to be tagged with additional metadata. We might want to indicate which data entry field is the one with a problem, or perhaps provide a tag for machine consumption that identifies which specific problem was encountered.

Read more »

Extending validation with warnings

Saturday, September 08 2018 validation csharp

If we cast back our thoughts back to the start of this series, one of the limitations of using string to return each of our errors was that every message has to be an error. What do we do if we want to support another kind of message?

Read more »

Validation recap

Saturday, August 25 2018 validation csharp

Let’s recap what we’ve achieved so far with our semantic types for validation. We’ve created a handful of types that work together to give a good model for capturing and processing object validation. The model starts with the base class ValidationResult and its subclasses:

Read more »

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 »

Older posts

Short-circuiting validation  11 Aug 2018
Aggregation of validation  04 Aug 2018
Recovery of validation types  28 Jul 2018
Basic validation  21 Jul 2018
Why we need better validation  07 Jul 2018
A question of struct performance  30 Jun 2018
Equality has Symmetry  17 Mar 2018
Type Miscellany  05 Mar 2017
Testing Immutable Types  25 Feb 2017
Factory Methods  18 Feb 2017
Queue Concatenation  11 Feb 2017
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