I 100% agree that F# does this better.
but saying "unless someone knows C# very well one could have easily gotten this wrong" is disingenuous at best.
Re:Why you should learn F#
by algorithmsRcool on Tuesday December 18, 2018 @04:32PM
(#18710789)
Dustin is definitely giving a hard sell here I conceed
But that struct example is less than great.
Just last night I had a readonly C# struct like that, that I used as a dictionary key and wondered why my perf tests took a nose dive when the Dictionary hit a few dozen entries.
My boneheaded mistake was i forgot to override GetHashCode and Object.Equals. Great my perf was looking decent, but even then I was allocating 32 bytes of memory on every lookup.
I forgot I needed to also implement IEquatable<> to prevent boxing on calls to Object.Equals.
My little 2 item struct is 3 lines of definition and 7 lines of boiler plate to get it right. and my GetHashCode impl is suboptimal.
F# records do all of that for you. every time. automatically.