F# vs C# in Performance

Hi, I’m C# Developer and new to F#. I have many questions about F#.

1- F# have the future?

2- in Enterprise web development, Can I count on F#?

3- generally Which one performs better than the other C# or F#?

Hello,

1 - i do believe F# has a future and the proof is the age of the language, it’s not new and many features of F# go on to C# or other languges as well. For what I remember Don Syme , the creator of F#, developed generics at Microsoft Research and together with a team they brought generics to C# (now you can find them also in typescript). On a presentation from Luca Bolognese (one of the creators of LINQ for C#) from 2008 in vs2008 (https://channel9.msdn.com/Blogs/pdc2008/TL11), I saw that F# already had async/await “similar” pattern via async computation expression and bang operator (!). so you could say that most of “modern” C# comes from F#, and was there long time ago, tuples as well. And then with the Addition of type providers F# really is a modern and sort of un-rivalled language for me.

2a- for enterprise web development F# shines, because it runs on .netcore and it very nicely interoperates with C# projects within the same solution, or as .nuget package. being a CLI language (like C# and vb.net) it can do whatever those other 2 langs can do , and more actually. F# is also OO and has classes, interfaces and inheritance mostly like regular C# and sometimes with much neater code. Checkout Giraffe if you want an Aspnetcore setting but with a functional feeling (inspired by Suave, which is a complete F# server)

2b - also checkout type providers: Sql type provider: Fsharp.Data.SqlClient if you are a “dapper” dev, or FSharp.Data.SqlProvider if you are a EF/dbContext dev, or Json type provider from F# data, and you will automatically find an enterprise usage of F# . I believe it’s amazing

2c - ADT types and data/functions separation of F# really shines for domain modeling and ROP programming, as you can check this blog --> fsharpforfunandprofit

2d - you can code in microsoft VS, JetBrains rider, VScode, Xamarin studio (now vs for mac) - so one of the best IDE experiences

3a - I don’t think there is major performance differences since F# mostly compiles to .net types, but of course being functional first usually does have performance benefits, especially because concurrency becomes “trivial” .

3b - A peculiar functional style difference is for recursive functions, in C# you cannot really optimize the call stack of a recursive function, wheras if F# if you write a rec function as a tail call function, it will be stack optimized by the compiler, making memory “stack-overflow” exceptions impossible.

to sum-up everything C# can do F# can do, but the opposite is not true :slight_smile: , i suggest give F# a try (i suggest with type providers) and don’t be afraid by small differences, i believe a C# dev can get up to speed to basic F# in 1 week and also F# has more similarities for js and python devs as well in many things (REPL, and higher order function names for example - filter, map, etc)

2 Likes

amazing! Especially when used alongside the C# language.
thank you very much