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 C# code
“C# BAD PRACTICES: Learn how to make a good code by bad example” http://www.codeproject.com/Articles/1083348/Csharp-BAD-PRACTICES-Learn-how-to-make-a-good-code
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.
Update ??.03.2016 : Some more C# refactoring of this example by Ralf Westphahl here http://ralfw.de/2016/03/dont-let-cleaning-up-go-overboard/
Update 26.01.2017 : More C# refactoring by Pete Smith here https://gist.github.com/beyond-code-github/8711794c4d516cb6941d47274884b248
Update 26.01.2017 : Even more C# refactoring of this example by David Arno with C# 7 and Succinc<T> here http://www.davidarno.org/2017/01/26/using-c-7-and-succinct-to-give-f-a-run-for-its-money/
Update 27.01.2017 : An explanation of the F# code by Richard Dalton http://www.devjoy.com/2017/01/reading-f/
Update 27.01.2017 : Much more C# refactoring by Kenneth Truyers https://www.kenneth-truyers.net/2017/01/27/refactoring-taken-too-far/
Update 28.01.2017 : An similar F# refactoring , with a merged discout logic (do the domain owner like that?) by Jon Harrop https://gist.github.com/jdh30/b01279a6be91467c5887b72a7c2f303e
Update ??.??.2018 : await C# 8 refactoring // ToDo: check if this F# code was also possible with F# 1.9 (2007)