Hey! Many years ago I used C# professionally before F# was a commonly used language. Now it seems that F# has taken off too, and that much of the functionality (and language-style) is common between the two. If I was reaching for a .net language in 2022, how should I choose one over the other - are there specific use-cases that make one a better choice? Or some language features that really separate them? Thanks!
One of the common misconceptions is that F# is only useful for specific domains, like math or finance or the like. F# actually is a general-purpose programming language, and can basically do anything C# does but better (IMHO). Some benefits of using F# over C#:
- Correctness: due to a more advanced compiler and some language features (e.g. no
null
), F# code usually has less bug - Conciseness: you usually need less lines of code
- Expressiveness: F# is great to model your application’s domain
I’d also argue that F# is a better designed language than C# in that it has less syntax, less ways of doing the same thing and just seems to be more “fun” to write code in.
The main arguments against using F# are that functional programming is unfamiliar to many and that it is hard to find people that know F#. Personally, I think both arguments can be circumvented by having one or two people in your team that know F# help the others learn F#. As F# also supports object-oriented programming, transitioning from C# to F# can be a nice and gradual process.
Scott Wlaschin explains it much better than I can on Why use F#? | F# for fun and profit and Anything C# can do... | F# for fun and profit
One of the issues can be finding examples/tooling for newer dotnet features. For instance, last I checked, MAUI was not particularly F# friendly.