r/functionalprogramming • • Oct 11 '23
Question Between Scala and Clojure which is better to learn FP?
Title is the question, which would be a better vehicle to learn FP with. I’m sticking with JVM languages for now so these are my choices. I’m sure I’ll make my way to Haskell eventually.
Thanks!
19
Upvotes
19
u/Daenyth Oct 11 '23
Scala with typelevel stack is probably the best "pure fp" setting available in any language right now, including haskell.
I'm kind of surprised at all the people recommending clojure, since my experience is that fp without static types is kind of hell. One thing to keep in mind is that OOP isn't an opposite to functional programming. Imperative programming is. Most OOP is imperative but it absolutely doesn't have to be. Using classes and objects for code organization in a pure fp codebase is really quite nice. Doing otherwise leaks implementation details all over the codebase
23
u/Collaborologist Oct 11 '23
I vote Clojure. Idiomatic Clojure will set you on your FP way comfortably without the excess and non-FP aspects of Scala.
Imho
5
u/MonadTran Oct 12 '23
If you want to learn FP, start with Haskell. If you want to get stuff done in the JVM, start with Scala. Clojure would probably be "more functional" than Scala, but ultimately Lisp variants are more about the syntax, macros, and DSLs than a specific paradigm or type system. It could still be good to learn a Lisp after Haskell and Scala, but it's not going to be as mind-blowing as Haskell or as practical as Scala.
5
u/marcinzh Oct 14 '23
There is profound difference between:
With that intent, the choice is pretty much settled, isn't it? The only viable alternative, is going directly to Haskell.
13
u/FoldingF Oct 11 '23
If you're coming from no experience with FP, I'd probably go with Clojure.
If you have a lot of OOP experience, you could probably get the gist of it all with Scala.
4
u/Vagal_4D Oct 11 '23
Since you want to limit yourself to the JVM ecosystem, Clojure will be better to learn FP. Actually, I think scala is more interesting, but the mix between imperative, OOP and FP paradigms is too strong and eventually you'll trade the opportunity to use FP pattern to some imperative way to do the task.
If you go beyond the JVM options, OCaml seems the right choice. Better tutorials than Haskell, has OOP and imperative way of doing things but the support for these paradigms is poor and you see yourself forced to use FP instead, and since the multicore support in version 5 the language is experiencing a reviving.
I mean, ML family languages are easier to grasp than lisps (Clojure) and Scala (famous for their step learning curve). If Eta was an option, I'll certainly recommend that.
8
u/jherrlin Oct 11 '23
At least to me Clojure brings another very important aspect and that’s the interactive development environment. As far as I know you only get that from Lisps. So I recommend looking at Clojure.
3
u/Skiamakhos Oct 11 '23
Clojure for pure FP. Scala if you know OOP and are eager to be productive quickly & learning FP is of secondary importance. Personally I'd favour Clojure, I just like it better.
3
u/gusdavis84 Oct 12 '23
For me I would say clojure. Absolutely no question.
3
u/reformed_goon Oct 14 '23
Scala is very pure. Clojure is more fun. I use Elixir when I actually want to deploy something in production.
4
u/Voxelman Oct 11 '23
You have a third choice called Eta. This is a language similar to Haskell if you want to learn a language from the ML family instead of a LISP
https://eta-lang.org/
2
u/Velascu Oct 12 '23
Clojure, scala is some kind of remix between oop and fp. With clojure for the brave and true you'll get most of the concepts easily. If you want to go deeper go to haskell, btw monads aren't that fucked up to understand but they throw an abstract mathematical definition (which is technically wrong) to a thing that has a very particular usage. Same for functors. I'm no expert in haskell btw.
2
u/[deleted] Jun 06 '24
Scala is easier for someone who comes from Java. But it is not purely functional, while Clojure is.
5
u/davi_suga Oct 11 '23
Scala. It will be much easier to read and understand at first if you come from a non-lisp background. There is an excellent book called "Functional Programming in Scala" that recently got a 2nd edition. Scala will be able to teach you more "fp features", like algebraic data types, pattern matching and monads, that lack on clojure. Scala is considered a mix of FP and OOP, but the OOP part is for modularity and simple dependency injection. It will not distract you from your goal.
3
u/griffonrl Oct 11 '23
OCaml
3
u/f_of_g_of_x Oct 11 '23
Clojure. It's a lot closer to FP than Scala for many reasons, one of them is its built-in data structures are immutable. Also: LISP, REPL, macros, etc.
1
u/syXzor Oct 11 '23
Why the JVM constraint though? If you just wanted the best fp language then I'd recommend purescript.
0
u/[deleted] Oct 25 '24
[deleted] — view deleted comment