Live data from Hacker News

Why you should learn F#

dusted.codes

71–80 of 179 posts

Re: Why you should learn F#

#71
post #62
post #42

Earlier quoted context omitted.

It sounds like your (more or less) just using classes for just namespacing functions and allowing bundles of functions to get brought in?

I've definitely structured f# modules that way. The module exposes one function that "injects" the dependency into multiple other functions, and then returns them as a blob. I'm not sure if that's "the fsharp way" (i suspect it isn't) and maybe I'll look back on it some day and cringe, but it's working pretty well for some of my (admittedly small) side projects I'm tinkering with right now.

Yes, that's what I do too. "Service" modules contain all the functions, with all dependencies explicitly passed into them, and at the bottom of the module is an interface with the dependencies assumed injected and a factory function that takes all the dependencies and returns an object with that interface.

In general I use a suave functional styled api on the top, OO-style SOA in the middle, and mostly functional style at the bottom layer, something of an FP-OOP-FP sandwich. I jokingly call it sandwich oriented programming.

Re: Why you should learn F#

#72
post #45

"No matter if you are already a functional developer from a different community (Haskell, Clojure, Scala, etc.) or you are a complete newbie to functional programming (like I was 3 years ago) I think F# can equally impress you" -> "For this task and for the rest of this blog post I'll be comparing F# with C# in order to show some of the benefits." F# is neat, and I see why it's useful if you have a big .NET program a…

As someone said on HN a while ago: F# works better on Linux than OCaml does on Windows. I recently was trying to decide which new language to learn, and reduced the choices to F# and OCaml. The catch? I need something that works on both Windows and Linux. I first attempted OCaml, and gave up soon after starting. I could tell that fighting Windows would be a constant battle. So I went with F#.

And then of course, parallel computation is an issue with OCaml.

SML: Kind of lacks libraries. I did learn some SML in the past and loved it, but I want a language that will let me be about as productive as Python is. SML lacks a strong ecosystem.

Re: Why you should learn F#

#73
post #45

"No matter if you are already a functional developer from a different community (Haskell, Clojure, Scala, etc.) or you are a complete newbie to functional programming (like I was 3 years ago) I think F# can equally impress you" -> "For this task and for the rest of this blog post I'll be comparing F# with C# in order to show some of the benefits." F# is neat, and I see why it's useful if you have a big .NET program a…

As others have said, F# interesting language features are computation expressions, active patterns, units and type-providers. The library, platforms and ecosystem benefits are gravy. Though subjective, the syntax is clean too, being somewhere between an ML and Python.

Something that no one has mentioned yet is that F# is now among the fastest functional first programming languages. At least according to (take with a grain of salt) benchmarks like [1] and https://www.techempower.com/benchmarks/

[1] https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: Why you should learn F#

#74

Earlier quoted context omitted.

Your sort solution limits which algorithms can be used, because you can't pass in a Func which might need an additional parameter anymore. This is why most C# developers would use an interface for this. With an interface you add extra parameters or dependencies to the constructor of the concrete implementation. If this example wasn't sort algorithms but password hashing algorithms this would be clear. So yeah.. it pr…

Just to be clear, you are arguing the superiority of partial application/currying here right? Because your F# example is the same except it's trading Func , List for (int list -> int list)

I think I just tried to say that I didn't specifically intend to write very verbose C# to make a point. I tried to write good real world production C# and then compare it to how I have seen people do DI in real world F#, which is partial application in this case. There is other ways of doing it too, but this is the most common pattern I've seen.

Re: Why you should learn F#

#75
post #55

While I really like the concept of functional programming and F# is definitely on my list of practical useful languages to learn, this article is clearly written by someone who doesn't know C# very well. Take the "To hell with interfaces" example. public interface ISortAlgorithm { List Sort(List values); } public class QuickSort : ISortAlgorithm { public List Sort(List values) { // Do QuickSort return values; } } pub…

Your sort solution limits which algorithms can be used, because you can't pass in a Func which might need an additional parameter anymore. This is why most C# developers would use an interface for this. With an interface you add extra parameters or dependencies to the constructor of the concrete implementation. If this example wasn't sort algorithms but password hashing algorithms this would be clear. So yeah.. it pr…

"Your sort solution limits which algorithms can be used, because you can't pass in a Func which might need an additional parameter anymore" O RLY?

  void List Sort(List input, bool someParam){}

  var values = new List { 9, 1, 5, 7 };
  DoSomething(x => Sort(x, true), values);
  
Thanks for proving my point that you really don't know C#.

Re: Why you should learn F#

#76
post #55

While I really like the concept of functional programming and F# is definitely on my list of practical useful languages to learn, this article is clearly written by someone who doesn't know C# very well. Take the "To hell with interfaces" example. public interface ISortAlgorithm { List Sort(List values); } public class QuickSort : ISortAlgorithm { public List Sort(List values) { // Do QuickSort return values; } } pub…

You are right about the first example (although the F# version looks nicer =D) 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 ev…

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#

#77

Earlier quoted context omitted.

Your sort solution limits which algorithms can be used, because you can't pass in a Func which might need an additional parameter anymore. This is why most C# developers would use an interface for this. With an interface you add extra parameters or dependencies to the constructor of the concrete implementation. If this example wasn't sort algorithms but password hashing algorithms this would be clear. So yeah.. it pr…

Just to be clear, you are arguing the superiority of partial application/currying here right? Because your F# example is the same except it's trading Func , List for (int list -> int list)

Technically its passing 'a list -> 'a list, and only becoming an int array because thats the final input value. The fsharp functions are closer to the C# functions Func, List>

Re: Why you should learn F#

#78
post #76

Earlier quoted context omitted.

You are right about the first example (although the F# version looks nicer =D) 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 ev…

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.

Dustin is definitely giving a hard sell here I conceed

Re: Why you should learn F#

#79

Someone I interviewed some years back did their interview in F#. I didn't know F# and tried to make that abundantly clear to them, but they persisted nonetheless. I had messed around with O'Caml back in college and so at least had a passing familiarity with functional language concepts, but I really had no idea if what the candidate produced could be considered quality production code. That didn't help their chances…

Maybe they want to do F# in their job, in which case they successfully filtered you out. Although it might have been smarter for them to ask about F# in an earlier round, or pre interview.

Re: Why you should learn F#

#80
post #54

Honest question: As someone who does web development and is looking to learn a new programming language in 2018, would you recommend F# over Elixir (and why)?

I'd suggest try both.

The Elixir web world gets a lot more love than the F# one. F# always touts the advantage of living in the .NET world, but it means most things are built with C# in mind, not F#. There are F# frameworks, and they are nice, but the community is quite small. But the advantage is the .NET world has a vast amount of libraries for doing most things.

OTP and Elixir is a better story than F# equivalents. There are no lightweight isolated processes in .NET

Elixir also has macros ( a very sharp double edged sword ) which can make frameworks nice to use.

F# is stronger typing which is nice and often has the trait if it compiles, it works. Though the normal downsides of dynamic typing in Elixir are not so bad.

But the best thing is to try both and make up your own mind

Post reply on HN