Is the Scala language better than Java

Martin Odersky: "Scala is definitely still a pioneer"

heise Developer: At the age of fourteen, Scala has meanwhile become a mature programming language that, among other things, attracts over a thousand developers each year to the Scala Days, which take place in Europe and the USA. Tell me how it all started!

Martin Odersky: The beginnings came from Java, which I was busy with the years before. We had been thinking for a long time how to bring Java and functional programming together. The first language was called pizza and had moderate success. Then I wrote a successful Java compiler, the Borland compiler. Then I wrote a compiler that became the official Sun compiler javac from Java 1.4 and could handle generics.

But we wanted to bring functional programming to the Java platform. Back then, many did not believe that functional and object-oriented programming could be brought together. We already knew that it could be done theoretically, but the question was: Can it also be implemented in practice? Therefore it started under the title "Scala Experiment". In the meantime, one can say that the experiment was a success. We are now dealing with advanced questions such as tooling.

The tooling is better than its reputation

heise Developer: This is exactly what complaints were made at the beginning. Did this change? Is the toolset now comparable to that of Java?

Odersky: Java is of course a very high bar. Probably at most in .NET the tooling is as mature as in Java. But compared to other languages, Scala is now well positioned. The IDEs have been a problem for a long time, but IntelliJ is the tool of choice and very usable. VS Code is also likely to be at the same level in the foreseeable future. Eclipse is still a good alternative, but it is a more difficult platform.

The Scala compiler is also mature in the meantime. If you don't program Scala too acrobatically, the compiler is very fast - contrary to its reputation. Most of the time, the compilation is incremental anyway, and I don't see any problem with the compilation time in my projects.

In Scala there is with implicit and macros tremendous expressiveness to do very complicated things. Some frameworks use this very aggressively, and tons of code is generated at compile time. Tooling is therefore a challenge above all because people do very ambitious things with Scala, which puts the tools under stress.

heise developer: In the JavaScript environment, the trend for frameworks for some time has been that they first become leaner and more modular instead of offering even more functions and thus continuing to grow. Maybe that is what Scala is asking for.

Odersky: It is definitely the case. There was a very good blog post in the Scala community with the title "The Principle of Least Power": You should always choose the solution that is the least powerful but still solves the problem. And I think that's exactly right - especially with a language that is very capable of expressing things in libraries, it is easy to abuse it, i.e. to become too big and too expressive.

A language like Go is almost diametrically opposed to Scala. At its core, programmers have what there is, and nothing else can be done. You should program with the few generic types - and that's it. Scala is the exact opposite. There is very little in the language, but everything can be expressed through libraries. One must therefore appeal to library designers not to abuse this.

Deliberately reduced the pace

heise developer: You get the feeling that after all the innovations at the beginning, the pace of development at Scala has been greatly reduced. Does that mean that everything essential is now contained in language? Provocatively asked: is Scala still up-to-date?

Odersky: If you look at the language itself, that's true - there have been fewer developments in the last five years than before. You could now also say: Scala has won, because the features that Scala already had in the past are now also available in all other languages. Closures, for example, even if Scala wasn't the first to have one. Orientation towards expressions as well. Many things that Scala pioneered are standard today.

If you really want to be functional, immutable (unchangeable), that has an impact on many other things. For example, you also need a good collections library that is also immutable. Java is mutable by default and is not suitable for daily work. Scala is still a pioneer.

We have deliberately slowed down the pace in recent years. Many developers wanted their code bases to be stable. That's why we said: we're taking a break from the main line of Scala, and the redevelopment is happening in the Dotty project, which will be Scala’s next big step. It's just a project name: DOT stands for "Dependent Object Types". Based on this, we have redeveloped the compiler and partly cleaned up the language. There will be several innovations that should also make the language easier to use.

heise developer: What is the time frame for the next language version based on Dotty.

Odersky: Dotty releases exist as developer previews and there are already some developers who use them. We plan to release the final version as Scala 3.0 in 2019.

heise developer: Are you happy that other languages ​​have adopted a lot from Scala, or do you see copying as competition.

Odersky: Well, I'm actually pretty relaxed about that. The important thing is the concepts, not whether it is this or that language. For me it is important how we can combine object-oriented programming for modularity and functional programming for elegance and security. And if other languages ​​do the same, then so much the better. Scala 3 will introduce some new concepts of its own, and hopefully other languages ​​will follow suit at some point.

Scala is not difficult to learn

heise developer: Still, Scala still has a reputation for being difficult to learn. What do you think about?

Odersky: From my point of view, this is absolutely not true. The first realization for me was that especially young people get along well with the language: If you put them in front of a Scala editor, they implement the projects very easily - much easier than in Java. There is no public, static, void, Main - all the conventions that you have to learn first.

The question arises, of course, where the call comes from. One problem could be: Because the language is so expressive, there is a wide range of possible programming styles, some of which also adapt concepts from other languages. For example, many concepts that were originally developed in the functional language Haskell are now also available as Scala libraries, which are often advertised with great enthusiasm. The Haskell port is anything but easy because Scala is not Haskell. It is sometimes amazing that this works at Scala at all. But if you take the approach as an introduction to Scala, then it can get complex.

But the problem is perhaps more general. Scala supports embedded Domain Specific Languages ​​(DSL) very well because it is so flexible. However, this can become a problem if the embedded DSLs themselves are complicated and difficult to use. Among other things, the Scala Build Tool is a DSL that is very powerful, but not easy. We have to do something simpler.

An interesting analogy is that Scala is complex in the same sense as the game Go. That means: The basic rules of Go are simple, but they can express positions and games of extraordinary complexity. The analogy is not perfect since the syntax and rules of Scala are of course more extensive than the rules of Go. But compared to other statically typed languages, Scala is relatively compact. So the comparison is already going in the right direction.

heise developer: Does Scala have advantages in the area of ​​machine learning (ML), for example in conjunction with Spark, which is written in Scala and supports it as a query language. When it comes to ML, you primarily come across Python.

Odersky: The trade-off is this: Python is very well established and there are more programmers who have mastered the language than Scala. But Scala has several advantages. Because the language is functional, it simplifies modeling. The second point is the types - static versus dynamic. Scala is statically typed, which is particularly helpful when it comes to reuse. A third advantage is that many of the frameworks such as Spark or Flink are largely written in Scala, so that the integration is better.

heise developer: Back to the other programming languages. Is there one that is currently particularly interesting for you?

Odersky: There are the languages ​​that are similar to Scala, and as already mentioned there are more and more of them. Kotlin, for example, adopts many of the Scala concepts, albeit omitting some of the more powerful ones, including higher-kinded types or Implicits.

Then of course it is also interesting to study languages ​​that do some things fundamentally differently. From that point of view, I would name two languages. One would be Rust to say, "OK, what do you do if you don't have a garbage collector?" That's an interesting problem. And among the languages ​​concerned, Rust is probably the one with the most sophisticated type system. The second would be a language that goes much further than Scala with types for program verification. Idris or Agda, for example, are languages ​​in which one can also do program proofs with the type system. I would be interested in how practicable this is and how far you can get with it.

Imitation is the best form of flattery

heise developer: Don't you resent Kotlin for taking over so much from Scala?

Odersky: No, not at all. "Imitation is the best form of flattery". Basically, that's a validation that what we've done makes sense. Otherwise others would not have taken it over. Since Kotlin is quite similar to Scala, but conceptually located between Java and Scala, it could also help to reduce inhibitions of Java programmers towards Scala.

heise developer: Are there any concepts that you would like to bring to Scala from other languages?

Odersky: Yes, but different. Some of the very advanced functional languages ​​are purely functional languages ​​- that means that you can statically distinguish between the types whether a calculation is a mathematical function, i.e. has no side effects, or whether it is a procedure that returns a result, but can have side effects. This is often important when it comes to high reliability and robustness. For example, Haskell has I / O monads to express that. In Scala we also want to get to the point where we can statically express whether something is functional or not, but we don't want to use monads for it. We think we've found something for it, but we still have to try it out to see if it works.

Three subject areas in which Scala shines

heise Developer: Finally: Which developers who have not yet touched Scala should look at the programming language? So for which subject areas do you particularly recommend Scala.

Odersky: I want to single out three areas: First, the area of ​​data science, big data and machine learning. Scala is already quite big, but still not as established as Python, for example.

Scala Days Europe

Martin Odersky will open Scala Days Europe with his keynote. The specialist conference on Scala will take place from May 14th to 17th in Berlin. The organizers are Lightbend, heise developer and dpunkt.verlag.

Second, definitely reactive, in the sense of distributed programming, programming for the cloud, where reactive programming is part of everyday life. There are Scala libraries with very well thought-out, tried and tested functions compared to what other systems have. I hope that programmers find their way to Scala through Akka and Play, for example.

And the third, where Scala is more of an outsider: Scala.js, i.e. Scala on JavaScript. This is an extremely capable implementation, but it is currently mainly used by Scala developers who want the frontend. But I think Scala.js is also something other people coming from JavaScript could look at. (rme)

The questions were asked by Rainald Menge-Sonnentag.