BT

DDD and CQRS Using the Functional Language F#

by Jan Stenberg on Mar 31, 2014 |

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.

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

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT