DDD and CQRS Using the Functional Language F#

| by Jan Stenberg Follow 28 Followers on Mar 31, 2014. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

A focus on behaviour and a more declarative style of code are two benefits for Domain-Driven Design (DDD) when moving from an object-oriented language like C# to a functional one like F#, Lev Gorodinski claims in a recent presentation, using an example that includes event sourcing and Command-Query Responsibility Separation (CQRS).

Lev has been using F# heavily during the last year and exclusively for the last 8 months and in his presentation he uses an example based on Greg Young’s original CQRS example to demonstrate how a F# implementation contrasts with a C# one, showing some of the benefits and challenges.

Implementing his example in a typical object-oriented approach Lev finds a number of issues, e.g. it’s quite verbose, and the entities have a dependency to the event source implementation.
In the F# implementation though there are improvements, it’s a lot less code, e.g. boilerplate code, which makes it less verbose, and the code is more explicit, capturing what happens in a function without hidden side effects.

Using DDD with an F# approach gives for Lev some benefits, it lets him focus on behaviour as opposed to the infrastructure required to implement it, which also means moving away from a CRUD thinking. It also supports a more declarative code; instead of writing code, it’s more about declaring a specification, with F# implementing the specification.
Lev points out that the benefits are all tenants of DDD and listed in two of the DDD books, written by Eric Evans and Vaughn Vernon respectively.

One of the challenges Lev experienced when moving to F# was the new paradigm, when he started he was doing C# style of code but in F#, which took a while to overcome to really make a shift to functional programming. It’s also a language that supports both functional and object oriented programming and sometimes he finds it hard to decide which option to use.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you