InfoQ Homepage News DDD and CQRS Using the Functional Language F#

DDD and CQRS Using the Functional Language F#

This item in japanese


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


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.

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

Community comments

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

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


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.