5 ms·
As disclaimer, I've been a Scala zealot for the last 3 years. On Clojure vs Scala, usually comparisons are kind of unfair I think. As somebody interested in FP,
by bad_user 11y ago
As disclaimer, I've been a Scala zealot for the last 3 years. On Clojure vs Scala, usually comparisons are kind of unfair I think. As somebody interested in FP, I tried Clojure first. And FP being all about immutable data-structures, pure functions operating on immutable data-structures and dealing with side-effects explicitly by means of abstractions such as the I/O Monad, I expected to see that in Clojure, seeing how people describe it as being very FP.
And it was like a big WTF for me seeing how for example everything in Clojure is a Var that can be changed. And eventually I got it, I mean Clojure is a LISP and it's meant to be compiled by a REPL and the unit of compilation is not a file and this is in LISP's tradition and so on and so forth. But it's still a WTF given its usual characterization. Even in Java classes are completely immutable (until you start manipulating bytecode of course) and you've got "final" declarations. You have no "final" in Clojure. And this is actually a pity because it (probably) means that those persistent data-structures can't be implemented in Clojure, as "final" on top of the JVM comes with a pretty cool contract in the Java Memory Model that you need. And then instead of Scala's implicit parameters, that are actually very explicit and type-checked by the compiler, in Clojure you have package-wide vars or refs that people manipulate as a poor man's dependency injection mechanism. And state changes are usually done by mutating atoms. Well that's cool, in Scala people also do that, but in Scala you also have a mature implementation of the I/O monad and monad transformers if you want it, or various FRP libraries. And I'm sure that Clojure has plenty of libraries, but overall I feel that in Scala the ecosystem of design patterns borrowed-from-Haskell is more mature.
Scala provides mutable variants of its data-structures in the standard library. But that's not extra rope to hang yourself, because in Clojure the use cases still exist and people end up using Java's mutable data-structures instead. In Scala the blend of OOP and FP can sound overwhelming, but it's actually the healthiest blend of FP + OOP to ever come up in a programming language. And in Clojure, just because you can't declare a class, that doesn't mean that OOP doesn't exist. It does and the blend is not healthy. This is why "reify" and "proxy" exist and are used quite frequently. And things like clojure.lang.ISeq are a Java OOP interface and not a protocol. Basically Scala is trying to make the best of OOP, whereas Clojure considers it a necessary evil of the host platform that it can't get rid of. Pick your poison.
- pjmlp 11y ago> In Scala the blend of OOP and FP can sound overwhelming, but it's actually the healthiest blend of FP + OOP to ever come up in a programming language. Have you tried OCaml or F#?
- whateveracct 11y agoScala is definitely a better blend of FP and OOP than either of those languages. It's also a heavier FP language that either of those.
- pjmlp 11y agoI fail to see how.
- justthistime_ 11y agoScala is more functional because it encourages immutability more strongly and allows better abstractions like typeclasses, higher-kinded types while being roughly even on the modularity front with OCaml (there are a few things easier done in OCaml and a few things easier done in Scala) and beating the shit out of F#. Not having a separate module and object system is another plus when compared to OCaml. It unifies OO and FP better than OCaml and F#, because OO implemented in OCaml and F# feels like the designers tried to make a point about how much they dislike OO. What's the first thing OCaml/F# devs tell others about OO in their langauge? To avoid it.
- tel 11y agoThey tell people to avoid the things called objects in OCaml which essentially are just row-typed dynamic records and an inheritance system. Really it's the inheritance system people are taught to avoid... Same as anyone in OO is being taught now. OTOH OCaml, as an ML, inherits an outstanding module story which is really the core of OO anyway. I'd happily say OCaml is a better OO language than Scala for that reason.