Most recently,
an article appeared on Habré, which gives an incorrect idea of the current state of affairs in the Scala community. The reader has a false impression of stagnation and decay in the Scala ecosystem. In this article, I would like to correct this and tell you about the recent updates and future changes.
In May 2016, at the Scala Days conference in New York, Martin Oderski presented a
presentation describing the present and future of the Scala language.
Scala 2.12
In November 2016, the new version of the Scala compiler version 2.12 was released, in which the traits are compiled directly into Java interfaces with default methods, and the lambda functions in Scala and Java are fully compatible, so that they can be called in both directions equally conveniently. It also contributed to improving the performance of Scala code on JRE 8.
Scala 2.13
On the new release of the scalac compiler, the standard library is refactored. Particular attention will be paid to the collections and perhaps the standard library will be divided into a compact core and a platform, which will include everything that does not fall into the core. It seems that the development of the scalac is stalling on the spot. Perhaps this is partly true, because the little thing is being developed now for the new Scala compiler, baptized Dotty in honor of the theory of dependent types on which it is based.
')
Scala dotty
The development of a
new compiler has been underway for several years by the EPFL team led by Martin Odersky. In addition to him, the team’s core includes 5 more people, including Dmitry Petrashko from
Habrovsk, aka
darkdimius . The core of the new version of the language is the Dependent Object Types calculus, designed by Martin Oderski specifically for the needs of Scala.
Due to the new compiler structure, the essence of which is explained in
this video , the compilation speed is already twice as fast as in scalac. And this is also taking into account the fact that developers have not even started optimizing the compiler yet. So all myths already outdated at the moment about the inconvenience of Scala's brake compilation will be completely debunked.
In Dotty, the type system will be updated, unused language features will be removed. Many things will be greatly simplified. But these are all abstract words. Let's quickly go to the examples.
First, go through what was removed for uselessness.
- Procedural syntax
- Classes with DelayedInit
- Reflection-based macros
- Early initialization of traits
- Existential types
- Projections of generic types
- XML inserts in the code
Instead, all the new improved features were added:
In the current form, the dotc compiler can be tested on
this test project . In the future, it is promised to add new features to the language.
- Implicit functional types
type CtxS = implicit Context => S def f(x:T):CtxS = { ... implicitly[Context] ... } f(e)
- Along with the usual features, effects will appear to ensure cleanliness.
A => B (can be impure) A -> B (pure)
- Normal types cannot be null by default. Values coming from Java code will always be optional.
T? = T | Null val stream: PrintStream? = System.out.printStream
- The magic number 22 will no longer scare Scala developers. Tuple22 / Function22 / Product22 will be history
type (S, T, U) = (S, (T, (U, Unit)))
- New data type records. Something of type with names. There is no example code. This is still the most mystical concept of the presented.
Also in Dotty, the Tasty system was designed to not recompile the libraries for each version of the compiler, which was problematic in Scala 2. And compared to the second version of Scala, Dotty promises to make good
explanations for compilation errors.
Dotty linker
The crown on Dotty's crown is
Linker , developed by Dmitry Petrashko. This is an optimizer that allows you to compile code exclusively for the types that are actually used. This allows you to achieve a serious reduction in the amount of code and increase productivity. With the linker, even the performance of the link libraries is greatly improved. You can find out more about this wonderful optimizer in
this video .
Scala meta
Instead of old macros, new convenient
Scala Meta macros, developed by Eugene Burmako, are published. So far they have been released only for Scala 2.11 and only for annotations, but not methods. But we can already say that they turned out much more convenient than the previous version. Now the macro declaration and its implementation are not separated, and working with syntactic trees is just great. Also, scala.meta works with source trees, and not with already slightly converted as macros, based on the old scala.reflect.
You can read more about them in this
tutorial .
Scala js
Scala.js compiles Scala code into high-performance Javascript code. Together with
Scalatags and
ScalaCSS , full-fledged web-frontend development becomes possible. A huge plus is the ability to share entities between the client and the server, and use the remote procedure call instead of the HTTP API explicit definition. In the past few years, several well-established and used in production frameworks with reactive binders like
Udash have appeared . Many developers use Scala.js, because they do not want to suffer with dynamic and "strange" JS. I will give an example used in official documentation.
javascript> ["10", "10", "10", "10"].map(parseInt) [10, NaN, 2, 3] // What??? scala> List("10", "10", "10", "10").map(parseInt) List(10, 10, 10, 10) // That's it
Scala native
Scala Native recently released a compiler in a native binary based on LLVM. This allows you to write instantly running code on Scala and use low-level data structures.
Macroid and RoboScala
Since Scala compiles to Java code, it is possible to use this language for developing for Android. To do this, there is a specialized Macroid
library , providing a convenient Android API. It is also possible to compile Scala code on IOS using RoboScala - wrappers around
RoboVMScalaFX
For the development of desktop software there is a library
ScalaFX , which is a wrapper around the famous JavaFX.
Conclusion
Although the article turned out to be very messy, it can serve as a good list of links to various Scala compilation tools for various platforms, and a source of information on future developments and features. All the tools and compilers presented in the article are actively developed, improved and used. So there’s no stagnation or even decay in the Scala ecosystem.