I spent a lot of time over the last couple of years learning F#. Over the last six months, I’ve spent most of my time learning and working in Scala. During part of both those times, I was working on the same set of code, ported to both languages. So, though this topic has been covered before, I thought I’d add my few observations from that experience to the great F# vs. Scala debate.
1) From the standpoint of most programmers, the choice of F# vs. Scala is probably determined by a single external factor: whether one is targeting the .NET ecosystem or the Java ecosystem. So the real-world debate is less likely to be F# vs. Scala than it is to be F# vs. C# or Scala vs. Java.
2) If you know F#, you already know all the really hard stuff you need to know about Scala, and vice versa. Now I’m not saying there’s 100% overlap between the two languages; each has features and quirks that the other lacks. But if you’ve reasonably mastered either, you’ve already gotten into the functional/mixed paradigm mindset. You’ve scaled the cliffs of type inference, case classes, pattern matching, first-class functions, currying, continuations, monads, etc. To move from F# to Scala or vice versa, you may have to learn moderately different ways to express those ideas, but you don’t have to make the climb all over.
Now the more technical stuff:
3) F# syntax is austere and a clean break with the curly brace world, whereas Scala retains much of the curly brace look and feel (while significantly cleaning it up). This was a deliberate decision on the part of the designers of Scala to ease the transition from Java. The result depends on your viewpoint: F# code is a more succinct if you’re used to reading it, but Scala is a little friendlier for newcomers.
4) Both languages are multi-paradigm, but F# favors functional programming whereas Scala favors object-oriented programming. This is not intended as a comment on the capabilities of the two languages, but rather on the “feel.” Both are clearly multi-paradigm, it’s just that on an FP to OOP scale of 0 – 9, F# feels more like a 4, and Scala feels more like a 6.
5) Scala programming rests on a foundation of traits, mixins, and the explicit management of types. Programmers making either the transition Java -> Scala, or C# -> F# -> Scala, will need to spend time mastering these concepts in order to take full advantage of Scala’s capabilities. (F# programmers from more academic backgrounds will already be more familiar with these things.)
6) F#’s higher-order libraries feel a little more pragmatic than do Scala’s. It’s not that you can do something in F# that you can’t do in Scala, it’s just that I’m often able to find a more precise higher-ordered function quicker in the F# documentation than in the Scala documentation. (To be fair to Scala, the libraries are evolving, and tend to get cleaner in each version.)
7) If you’re a .NET programmer without much open-source experience, getting started using Scala is likely to be both terrifying and exhilarating. What I mean is: if you do .NET programming, you have Visual Studio, and if you have Visual Studio, you have F#, and the F# you have just works – there, out-of-the box, batteries included. To do Scala, on the other hand, you’re going to have to put together a toolkit for yourself, sometimes pulling resources from various open-source concerns. But there are a couple of pieces of good news to temper this: first, Scala is much easier in this regard than much open-source software I’ve encountered; second, the inventors of Scala have started a concern called Typesafe to help centralize these resources (see sidebar links under Scala).
8) The community experience is excellent in both cases. Both the F# and the Scala communities are filled with excellent programmers who are passionate about the discipline. The users and committers of the two languages are their greatest assets.
I’ll end with two metaphors, the first about F# and Scala themselves, and the second about the two communities:
F# and Scala remind me of the cases of convergent evolution in the biological world. They have evolved in different ecosystems, but similar selection pressure has resulted in similar outcomes. And some of those pressures are among the most important in all of computing: correctness, concurrency, distributed computing, and maintainability.
And lastly, the F# and Scala communities are less like two rival groups of barbarians storming the same castle than they are like one group of barbarians temporarily divided so they can storm two different castles. (And storm them for their own good, lol.)