by azinman2 · 7y ago · 0 comments
I used to be a Scala enthusiast before these alternatives existed. What place does Scala now have in the world?
If you want Java++, the best Java++ is still Java with a bunch of libraries. You don't need a new language for that.
Kotlin's succes is effectively because Google was late to port Java 8 to Android. A fine language btw, but it will either become more like Scala, or it will wither away eventually. My bet is in it becoming more like Scala, as evidenced by arrow-kt.io
Scala has a blend of features that makes it the most expressive mainstream functional programming language, most importantly ... implicits, by which you can model typeclasses and higher kinded types.
And in Scala we've got an active community of FP libraries. Actual FP, emphasizing referential transparency, with abstractions built for suspending effects.
It's a little known fact but the kind of FP programming we do in Scala tends to be more pure than what happens in OCaml, F#, Erlang, Clojure and others.
Also, we have a Scala to Javascript compiler, all the tooling works with it and we've got an ecosystem of libraries cross-compiled to Javascript.
As for Scala Native, it has its place. The problem has been lack of manpower to bring it to the maturity that Scala.js is at.
I have only dabbled in Scala, but IMHO it's more suited as an OCaml with first-class modules. Why not use Haskell, if you don't need the JVM?
For-comprehensions are worse than Haskell's do-notation or compared with F#'s computation expressions, but the list ends there. In practice they work well and at least Scala has monadic for-comprehensions. How many other languages can claim that?
As for performance, I encourage you to take a look at the state of the art. Working with our IO Monads has better performance than many abstractions that people now take for granted, like most Future/Promise implementations.
I build systems that are super stressed by incoming traffic and Scala's performance is awesome. Worse than bare metal Java of course, but when you compare it with high level Java frameworks or with Python/Ruby/Javascript/what have you, you'd actually be surprised by how better Scala FP is ;-)
As for Haskell, I like the language, but it's super fragmented, everyone has its own Prelude and favorite language extensions, extensions that are sometimes in conflict with other extensions and the tooling is a mess. Also laziness is cool, but performance gets hard to predict. We have the same problem in Scala when we are using lazy abstractions actually, the difference being that Scala is opt-in instead of opt-out.
With Scala, even if you're targeting JS instead of the JVM, you still use the same tools.
And I even like the language better. Scala 3 will fix many annoyances I have, including adding untagged unions and GADTs that are based on ADTs, in other words nicer than Haskell.
PureScript I would like though, as it fixes some of Haskell's problems, maybe one day it won't be limited to JS.
Not an expert in Haskell, nor Scala - only dabbling. However, the above could be repeated verbatim after replacing Haskell with Scala, couldn't it? You can write Java++, Haskell-- or any combination in between. Use one of the several FP stacks or build tools.
I think both Scala, Haskell and C++ can compete for the name of the most complicated, fragmented and diverse language and ecosystem in existence.
I really like Haskell, but this aspect of the use of Haskell also bothers me. I use a small subset of Haskell and language extensions, a small subset that I am happy and productive with, but it takes me a lot of effort to understand other people’s code.
In my Haskell experience (including some professional experience) this isn't the case very often at all (maybe not even as often as it should be).
(Which is not to say that there aren't some problems with fragmentation elsewhere in Haskell's ecosystem)
Could you name two widely-used extensions that conflict with each other in a non-trivial way? I've used Haskell for several years and I've never come across any.
What do you mean by pure exactly? IO Monad? Simply no side effects?
> “The IO monad does not make a function pure. It just makes it obvious that it’s impure.”
https://groups.google.com/forum/#!topic/scala-debate/xYlUlQA...
In particular, pointer arithmetic and memory allocation feel really smooth, and struct syntax is getting reworked for the upcoming SN 0.4 release.
The affinity with C, and with systems programming in general, isn't something you necessarily get with Swift or OCaml to the same extent. And even Rust, although it is outstanding for some systems tasks, isn't 100% mature on concurrency and async use cases yet.
In contrast, Scala Native works really nicely for low-level concurrent programming - I'm writing a book about SN for Pragmatic at the moment [1], and the entire second half is about building up a fully concurrent backend service framework, from scratch, using C libraries like libuv and libcurl. We're also preparing to release an official libuv binding for Scala Native 0.4 [2]
1: https://pragprog.com/book/rwscala/modern-systems-programming...
As for scala-native, it gets past the major draw backs of the JVM: startup speed, memory size, and Oracle. From applets in 2002 to kubernetes sidecars and aws lambda today, the JVM refuses to optimize for these things.
Currently Scala.Native still performs poorly than Scala JVM.
Since 2000 anyone that cared about AOT in Java had quite a few commercial Java vendors that offered AOT on their JDKs, Oracle and IBM were two of them.
Project Panama, Valhalla, Metropolis and Graal are proof that Java community does care to optimize for these things.
This is factually incorrect [1]. 0.4.0 series is shipping with brand new optimizer (as of M1) and soon a parallel garbage collector (M3). Both contribute to major performance overhaul compared to the current stable 0.3 branch (see benchmarks on the link below).
[1] https://github.com/scala-native/scala-native/releases/tag/v0...
> proof that Java community does care
Oh, the community wants them. It's been Sun then Oracle and now the OpenJDK project that has never prioritized these things and that's the runtime 99% of JVM shops run.
Scala's position in the standard JVM world hasn't changed too much. Kotlin has taken up some of the "better Java" part of Scala, but otherwise Scala still maintains its niche of statically typed FP (mixed in with OO) on the JVM.
Scala on Android has withered (Kotlin really took off here). Scala Native unfortunately also has kind of withered too, but GraalVM picks up the slack there in allowing for native compilation.
Scala.js (compiling Scala to Javascript) has become surprisingly mature.
serious answer: chisel3
other serious answer (at least to me): the ability to write incredibly terse code. For instance Rust, as great as it is, doesn’t have partial application.
iter.map(|x, y| f(x.as_ref(), y))?
is so much less satisfying than iter.map(f(_, _))
I’m pretty sure you could recover that behavior using a compiler plugin, though.Also, don’t get me started on implicit conversions... I’m an avid golfer.
Other than not having (usable) macros, the language itself has very nice amenities. SBT was like an early Cargo, even.
If I have to inherit code, I'd take (JavaScript|Rails|PHP|Python)+(MySQL|PostgreSQL) over (Scala|Haskell|F#|Lisp)+(MongoDB|Cassandra|Kafka) any day.
I understand that all of these tools have their uses, but the most important thing is ease of finding decent developers. Lots of people can do JavaScript well, but few can do Scala, so you're going to have a smaller pool of talent. More popular languages are also going to have more developed patterns, more native libraries, and better tooling options.
If you need Scala, please just write Java. You'll always be able to hire a Java dev. Everyone hates writing Java, but everyone can write Java.
And related, if you're using any kind of NoSQL for your business data, you're wrong. I understand NoSQL for caching and document storage, but not everything is a document. Most things are actually best in SQL tables. Especially if you're a startup.
Or you can define a sane coding standard and subset that your team agrees is readable, and stick with it, and enforce it through code review.
This is what killed scala to me. It talks up a big story about Java interop, but the reality is that the separate collections really drive a wedge between the scala ecosystem and the rest of the JVM world so it does not have the kind of seamless iterop that Kotlin and (especially) Groovy do.
Also arrays are one place where Scala and Java do happen to share the same collection.
As you accurately pointed out for a "better" Java you probably want Kotlin - which has better compatibility with Java, is supported by big players (JetBrains, Google) and because of being the blessed language for Android is growing in popularity very fast.
I think GP meant the place of Scala Native, where being a JVM language is irrelevant.
With Cats or ScalaZ you can get Haskell-like syntax, and the advantage over Haskell is that Scala runs in the JVM and it provides interop with Java libraries.