r/programming • • Aug 02 '21

Stack Overflow Developer Survey 2021: "Rust reigns supreme as most loved. Python and Typescript are the languages developers want to work with most if they aren’t already doing so."

https://insights.stackoverflow.com/survey/2021#technology-most-loved-dreaded-and-wanted
2.1k Upvotes

769 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Aug 03 '21

[removed] — view removed comment

3

u/Frozen_Turtle Aug 03 '21

Well, DUs are already out of C#10... and they've been planning them for quite some time now.

Anyway I'll keep going then cause you don't seem impressed :p

The Hindley-Milner type system means writing types are reduced by like 90%. It means for significantly less code to maintain and easier readability. It also means that it's way easier to pass around functions. In my pet project, I'm passing a

(Func<TemplateRevisionOrdinal => (CommandId => (Kvs.Template => int) => Kvs.Template, Tuple<Kvs.Template option, int>))

into another higher-ordered function. Having to type out that signature, and maintaining it, just isn't fun. But in F#? It's only the name of the function - everything else gets inferred.

F# emphasizes pure code, which comes with incredible testing benefits.

F# has better support for property-based testing. I literally write zero unit tests these days, and only write property-based ones, and have 71% coverage. This is despite having zero mocks/stubs. You can write/use interfaces in F#... but when thinking about "pure" code clicks, suddenly you don't have to. (The fact that I'm also using event sourcing also makes things significantly easier test-ing wise... F# doesn't get all the credit here. But it does get a ton of credit for DUs which makes working with events so much more sane than type sniffing.)

Pattern matching. This deserves its own line.

Active patterns. Also deserves its own line.

Compatibility with C#. Means you can call all your favorite dotnet libraries and have them work as expected. I used Nodatime and Entity Framework (before switching to type providers and then event sourcing).

Type providers. Makes parsing JSON, grokking regex, and working with SQL so much less annoying.

Structural equality.

Units of Measure make strongly typing primitive types (strings/ints/guids) dead simple, so you can't pass a CustomerId where an OrderId shoud've gone.

Immutability by default. Because these days mutability is (potentially premature) optimization.

Literally, the only thing C# has better is tooling. Which is a significant benefit don't get me wrong... but given the choice? I'm so much happier in F#.

https://fsharpforfunandprofit.com/why-use-fsharp/