An F# rewrite of a fully refactored C# Clean Code example

Today I stumbled over a C# clean code refactoring example, where I could not resist to do a full rewrite in F# during my break.

The reason for doing this was mainly to present a comparison how does a piece of deeply refactored C# code can look in F#, to motivate others to learn F#, because it makes things (software: thinking, design, coding, review and tests) much simpler and leads to robust solutions.

And the other reason was to show the nice F# syntax coloring that is possible with the Visual F# Power Tools (VFPT) that is an excellent and must have add-on in VS-2015. This screenshot is taken with my customized coloring scheme.

The F# code

The C# code

“C# BAD PRACTICES: Learn how to make a good code by bad example”

If you like to have deep detailed F# training please see our F# 2-day course information (German language).

Ok that’s it, I hope you got some new ideas by comparing the F# and C# code.

??.03.2016 : Some more C# refactoring of this example by Ralf Westphahl here

Update 26.01.2017 : More C# refactoring by Pete Smith here

Update 26.01.2017 : Even more C# refactoring of this example by David Arno with C# 7 and Succinc<T> here

Update 27.01.2017 : An explanation of the F# code by Richard Dalton

Update 27.01.2017 : Much more C# refactoring by Kenneth Truyers

Update 28.01.2017 : An similar F# refactoring , with a merged discout logic (do the domain owner like that?) by Jon Harrop

Update ??.??.2018 : await C# 8 refactoring // ToDo: check if this F# code was also possible with F# 1.9 (2007)