What's so great about Scala?

Don Werve picture Don Werve · Apr 7, 2009 · Viewed 32.7k times · Source

What makes Scala such a wonderful language, other than the type system? Almost everything I read about the language brings out 'strong typing' as a big reason to use Scala, but there has to be more than that. What are some of the other compelling and/or cool language features that make Scala a really useful tool?

Answer

andri picture andri · Apr 7, 2009

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.