News for hackers. Stuff that matters.
Re:Why you should learn F# by thedirt0115 on Tuesday December 18, 2018 @08:51PM (#18712379)
I don't know F#, but I do know C#, and it feels like the author is trying to make C# look more difficult/verbose than it needs to be to make F# look better. Here is an alternative version of the "Everything is a function" section's IPasswordPolicy thing: https://ideone.com/3Savt9 I even went a little overboard with the function that takes a list of functions and returns a single composed function -- I could've also written a one-off that uses "&&" like the F# version: bool isValidCustom(pw) { return f1(pw) && f2(pw) && ...; } Am I missing something? Why did the author make the C# version so complex??
Re:Why you should learn F# by algorithmsRcool on Tuesday December 18, 2018 @09:20PM (#18712498)
Well you're right of course. But my only thought here is that Dustin's code looks like idiomatic C#, but yours does not.

You can do function composition in C# but I've virtually (heh) never seen it. Classes and Interfaces are the default abstractions in C# land even if there are other available.

Re:Why you should learn F# by rjblackman on Tuesday December 18, 2018 @09:25PM (#18712521)
I haven't read the article in depth, but the authors example is written according to SOLID principles where composition is decoupled via interfaces and dependency injection. I think the author is trying to show the difference between highly decoupled code examples in c# and f#. In f# you compose with functions, in c# you compose with object instances.
Re:Why you should learn F# by cgrealy on Tuesday December 18, 2018 @09:35PM (#18712567)
Actually you can make it even more concise with an inferred array

  var isValidShort = createPasswordPolicy(new [] {
        	Test.MinimumLength(8),
        	Test.MustHaveDigits,
        	Test.MustHaveUppercase,
        });