Ian Wold

Book Club 10/2023: Functional Patterns in C#

27 October 2023 2 Minutes History Patterns Languages Dotnet

This month I've focused on functional domain modeling and related patterns. We're just a few weeks away from the release of the next version of C#, and like each previous version it'll introduce even more functional features.

hero

Happy spooky season!

This month I've focused on functional domain modeling and related patterns. We're just a few weeks away from the release of the next version of C#, and like each previous version it'll introduce even more functional features. We still aren't getting discriminated unions, but as C# becomes more functional, these patterns are becoming increasingly more attractive. Traditionally, C# is written in OO or procedural styles, and from my perspective there doesn't seem to be a great deal of discussion among C# engineers about incorporating functional patterns. Maybe you run in different circles, but I think there's room for improvement across the board here. Even the result monad, which can be used within an entirely OO context, is infrequently implemented.

I think it's important to be discussing functional patterns in C#, for a few practical reasons:

  • Eventually we're getting DU, and that's going to change a lot of things
  • Our F# colleagues are doing great work in this area, we should engage them more
  • Using functional patterns is cool

But above all, if C# supports these patterns and they can help us write better code, why would we neglect them? To explore this topic, I've curated a set of talks by Scott Wlaschin and Mark Seemann who both do a great job explaining functional programming from a conceptual perspective, demonstrating its power in F#, and ultimately demonstrating C# equivalents.

I hope these talks make you all as excited for discriminated unions in C# as I am!