What risks are involved if I work in a C# shop and I attempt to write a feature in F# and then rely on ILSpy to translate the F# source code to a C# representation?
Asked
Active
Viewed 218 times
2
-
11You will most certainly have unreadable and unmaintainable C# code – Petr Dec 01 '15 at 17:39
-
9This blog post has many good ideas on low-risk ways of starting with F# at work: http://fsharpforfunandprofit.com/series/low-risk-ways-to-use-fsharp-at-work.html Using ILSpy to convert F# to C# is definitely _not_ one of them. – Tomas Petricek Dec 01 '15 at 17:43
1 Answers
9
I would very strongly recommend against doing this.
- F# code that has been decompiled into C# tends to be extremely verbose and unreadable. It will be near impossible for anyone who doesn't possess a copy of the original F# code to understand or maintain.
- Functional code gives you opportunities for code reuse that you wouldn't have in an OO language. The C# code produced by decompiling probably wouldn't offer (m)any avenues of reuse beyond the boundaries of your decompiled F#.
- What's idiomatic in F# sometimes isn't in C#, that's particularly true after an intermediate stage of decompilation. The code would likely not pass a review process.
- Units of measure and
inline
functions with static type constraints are both features of the F# compiler rather something provided by .NET. You might gain some advantage from them by using the decompiled C# directly but any modifications made to the C# source wouldn't be checked for e.g. dimensional correctness.
I would also second Tomas' suggestion of having a read through this article: http://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work/
I would suggest, however, that it could be worth having a conversation with your team/manager(s) about the possibility of introducing F# at your workplace.
My personal experience of using F# commercially is that development time often tends to be shorter (sometimes substantially) compared to the same project done in C# and it's usually easier to verify and test the result. These are advantages that are very appealing commercially.

TheInnerLight
- 12,034
- 1
- 29
- 52
-
Thanks InnerLight.Should I first write test automation support with this language before asking permission to implement business solutions with it? – Scott Nimrod Dec 02 '15 at 18:11
-
2@ScottNimrod It's tough for me to give you advise about how you should proceed when it comes to your company, ultimately you know your team better than I do. That said, anything you can do to demonstrate the business value of using F# is going to help your case. If you think it's going to be a hard sell, I would hold off until there is a situation where you know that FP/F# is really going to excel. In some cases, it's really pretty obvious it's a better choice for expressing a particular problem, in other cases that might be less obvious to those with little to no F# experience. – TheInnerLight Dec 02 '15 at 18:46