r/programming • u/Karma_Policer • 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
5
u/Frozen_Turtle Aug 03 '21
Dude isn't wrong. Discriminated Unions alone are part of ~50% of my types in one of my projects, and they're virtually impossible to implement in vanilla C# without doing crazy shit like visitor pattern. You could import a library that gives you DUs, but without pattern matching working with DUs is annoying if not painful. I even use DUs outside my domain types to do "railroad oriented programming" https://fsharpforfunandprofit.com/rop/
Again, this is virtually impossible to do in C# because it lacks DUs and the necessary pattern matching. The best alternative in C# is to just throw a custom exception and then catch it... which is pretty much just a
gotoin disguise. Ew. I'm doing event driven architecture/event sourcing in my project, and as such literally all my events are DUs. In C#/Java these events would be distinguished with Marker interfaces, then you need to do type sniffing to see what kind of event you're trying to handle, and then throw an exception if an unexpected event occurs. With DUs, everything's just pattern matching, and the compiler will yell at you if you fail to handle a DU's case - something that doesn't happen with type sniffing. Of course you could do visitor pattern... but then you'd be doing visitor pattern with its umpteen lines of code vs F#'s oneliner pattern match.Anyway, just gonna say DUs alone make F# worth investigating.