Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's so great about Scala? [closed]

People also ask

Why is Scala not popular?

It's because of the compiler and SBT to be frank. They are very very clunky. The compiler has gotten quite a bit faster since it started being measured. See https://scala-ci.typesafe.com/grafana/dashboard/db/scala-ben...

What is so good about Scala?

Scala combines object-oriented and functional programming in one concise, high-level language. Scala's static types help avoid bugs in complex applications, and its JVM and JavaScript runtimes let you build high-performance systems with easy access to huge ecosystems of libraries.

Is it worth learning Scala in 2022?

Scala is worth learning in 2022. The demand for Scala developers is high, and the pay is good. LinkedIn currently lists over 24,000 Scala jobs. According to ZipRecruiter, the average Scala developer salary in the United States is $139,292 a year.

Is Scala still relevant 2021?

Regardless of Scala's uncertain future in the Data Science ecosystem I think it is still a great language that is worth picking up. This is the case regardless of whether or not one plans to use the language for Data Science.


Here are some of the things that made me favour Scala (over, say, usual Java):

a) Type inference. The Java way of doing it:

Map<Something, List<SomethingElse>> list = new HashMap<Something, List<SomethingElse>>()

.. is rather verbose compared to Scala. The compiler should be able to figure it out if you give one of these lists.

b) First-order functions. Again, this functionality can be emulated with classes, but it's ugly.

c) Collections that have map and fold. These two tie in with (b), and also these two are something I wish for every time I have to write Java.

d) Pattern matching and case classes.

e) Variances, which mean that if S extends T, then List[S] extends List[T] as well.

Throw in some static types goodness as well, and I was sold on the language quite fast.


It's a mash up of the best bits from a bunch of languages, what's not to love:

  • Ruby's terse syntax
  • Java's performance
  • Erlang's Actor Support
  • Closures/Blocks
  • Convenient shorthand for maps & arrays

Scala is often paraded for having closures and implicits. Not surprising really, as lack of closures and explicit typing are perhaps the two biggest sources of Java boilerplate!

But once you examine it a little deeper, it goes far beyond Java-without-the-annoying bits, Perhaps the greatest strength of Scala is not one specific named feature, but how successful it is in unifying all of the features mentioned in other answers.

Post Functional

The union of object orientation and functional programming for example: Because functions are objects, Scala was able to make Maps implement the Function interface, so when you use a map to look up a value, it's no different syntactically from using a function to calculate a value. In unifying these paradigms so well, Scala truly is a post-functional language.

Or operator overloading, which is achieved by not actually having operators, they're just methods used in infix notation. So 1 + 2 is just calling the + method on an integer. If the method was named plus instead then you'd use it as 1 plus 2 which is no different from 1.plus(2). This is made possible because of another combination of features; everything in Scala is an object, there are no primitives, so integers can have methods.

Other Feature Fusion

Type classes were also mentioned, achieved by a combination of higher-kinded types, singleton objects, and implicits.

Other features that work well together are case classes and pattern matching, allowing you to easily build and deconstruct algebraic data types, without having to manually write all the tedious equality, hashcode, constructor and getter/setter logic that Java demands.

Specifying immutability by default, offering lazy values, and providing first class functions all combine to give you a language that's very suited to building efficient functional data structures.

The list goes on, but I've been using Scala for over 3 years now, and I'm still amazed almost daily at how well everything just works together.

Efficient and Versatile

Scala is also a small language, with a spec that (surprisingly!) only needs to be around 1/3 the size of Java's. This is partly because Java has a lot of special cases in the spec that Scala simplifies away, partly because of removing features such as primitives and operators, and partly because a lot of functionality has been moved from the language and into the libraries.

As a benefit of this, all the techniques available to the Scala library authors are also available to any Scala user, which makes it a great language for defining your own control-flow constructs and for building DSLs. This has been used to great effect in projects like Akka - a 3rd-party Actor framework.

Deep

Finally, it scales the full range of programming styles.

The runtime interpreter (known as the REPL) allows you to very quickly explore ideas in an interactive session, and Scala files can also be run as scripts without needing explicit compilation. When coupled with type inference, this gives Scala the feel of a dynamic language such as Ruby, Perl, or a bash script.

At the other end of the spectrum, traits, classes, objects and self-types allow you to build a full-scale enterprise system based on distinct components and using dependency injection without the need of 3rd-party tools. Scala also integrates with Java libraries at a level almost on-par with native Java, and by running on the JVM can take advantage of all the speed benefits offered on that platform, as well as being perfectly usable in containers such as tomcat, or with OSGi.


I'm new to Scala, but my impression is:

Really good JVM integration will be the driving factor. JRuby can call java and java can call JRuby code, but it's explicitly calling into another language, not the clean integration of Scala-Java. So you can use Java libraries, and even mix and match in the same project.

I started looking at scala when I had a realization that the thing which will drive the next great language is easy concurrency. The JVM has good concurrency from a performance standpoint. I'm sure someone will say that Erlang is better, but Scala is actually usable by normal programmers.

Where Java falls down is that it's just so painfully verbose. It takes way too many characters to create and pass a Functor. Scala allows passing functions as arguments.

It isn't possible in Java to create a union type, or to apply an interface to an existing class. These are both easy in Scala.

Static typing usually has a big penalty of verboseness. Scala eliminates this downside while still giving the upside of static typing, which is compile time type checking, and it makes code assist in editors easier.

The ability to extend the language. This has been the thing that has kept Lisp going for decades, and that allowed Ruby on Rails.


The type system really is Scala's most distinguishing feature. It also has a lot of syntactic conveniences over, say, Java.

But for me, the most compelling features of Scala are:

  • First-class modules.
  • Higher-kinded types (type constructor polymorphism).
  • Implicits.

In effect, these features let you approximate (and in some ways surpass) Haskell's type classes. Combined, they let you write exceptionally modular code.