Introduction to the 'Why use F#' series (2012)
fsharpforfunandprofit.com
fsharpforfunandprofit.com
If you're into domain-driven design, I find F# makes it easier to model your code after your line of business. I also like how F# nudges my code into an "onion-layer" architecture, where the domain of my business logic is at the core and is wrapped around with functionality like reading and validating inputs from external sources.
I also like Elm and the idea of ReasonML, so I plan to seriously check out Fable, which compiles F# to Javascript, and Elmish. There's also Saturn, which is built on top of asp.net-core
Came here from 10 years of Scala with no .NET experience what so ever.
Just overall one of the nicest experiences so far. 9/10, would recommend!
Don't worry about advanced concepts, you'll get to those when / if you need them. They have their uses but it depends on what you're working on. I think many people just succumb to the blub paradox too quickly with these sorts of languages. It's a real shame.
It's honestly overstated how hard it is. I started as a junior dev with Scala and was highly productive within months. I don't think there's anything special about me. I was highly motivated by my love for the language I guess.
If I was starting from scratch and just wanted to learn, I'd say you'll learn plenty from any of them. Haskell has the most to teach about purity in FP, Scala the most about OOP, and Clojure the most about metaprogramming.
F# has the most to offer for just getting things done quickly. It is a language of practical compromises. It's not the most pure, it doesn't bring the most advanced OOP, and it's metaprogramming is tricky. However F# is what I grab first when I want to build production software quickly and safely.
The one thing I still wish I could have is some sort of higher-kinded polymorphism, because I think that could make the business domain modeling even easier than it already is. But, as a Scala dropout, I also appreciate the eminent sobriety of being so cautious about introducing features that would create friction with the rest of the ecosystem.
If I replaced F# for Scala in this paragraph it would sum up my feelings about Scala (swapping .net for Java obv).
I'm intrigued by F#, would love to try it one day. I definitely agree about the intersection between DDD and these sorts of FP languages. It's still not fully appreciated how nicely these two things fit together.
While I'm generally productive with Golang, I'm not really happy with the language itself. It's a bit too simplistic for my taste. F# on the other hand looks like pure elegance. The big question is how long it takes you to be really productive with it, say for a GraphQL/REST backend for some SPA. I'm also a bit worried about the small community. I guess if things go wrong, you can always fallback on C#. Any tips to get up to speed quickly?
That will give you a restful api using F# that you can immediately modify to build out an endpoint. Figure out how to add in authn/authz using just regular aspnet core and you'll be ready to go. I like dapper for data access in F#, but plenty prefer a more traditional ORM like nhibernate or EF6.
You'd be surprised how much you can do with F#, the only caveat is learning to read docs in C#. Since that's considered the lingua franca of .NET, almost all docs will be in C# and need to be transliterated into F#. This is a skill that only takes a day or two to learn.
Mono is no longer required to get started with F#. All you need now is .NET Core.
Extra keywords and extra files are annoyances that I try to instinctively minimise. I don't want to say I take the path of "least annoyance", but it's definitely one of the factors that strongly influence how I write code. F#'s lean tagged union type syntax is functionally inferior to Scala 2's case classes, but I use sum types more in F#, because they're less annoying. In C#, I might as well use classes, because I can't declare free functions.
I often hear that Java is good for teams, because it railroads programmers into writing maintainable, pure OOP code. Well, F# railroads you into writing data-driven, mostly functional, multi-paradigm code, and I think the result is much nicer code than what you'd get when trying that in most other languages.
If I had them as a first-class language feature, would I use them more? What for?
For example, in my biggest F# project I parse a local standard for public transport timetables. In that format a trip can either drive through a stop, drive around it or stop there at a particular time. With a sum type, I can represent all three of these cases without worrying about a value of that type having both "driving through" and a time set. When you've got a language that effortlessly allows something like this, you'll find uses for these paradigms.
1. Allows you to make failure scenarios intrinsic to your domain, and the compiler then is a tool for domain correctness.
2. It provides a beautiful symmetry between how you define your domain and how you operate on it. The syntax is even almost identical. The features "fit" incredibly well because of that.
Beyond that, with optionals and results defined as sum types you find that any time you're in a "It may explicitly give me nothing" or "It may explicitly give me an error" scenario these types are the first your reach for in your toolbag.
Sum types don't completely obviate classes, but they are a better tool than classes for several scenarios.
I think from the syntax, strong typing, and algebraic type signatures F# is the most information dense language I have come across, while still allowing for readability. Maybe something like brainfuck is more information dense.