Scala 2.13: Has Scala Done it Again?
Scala 2.13: Is it worth the hype?
Join the DZone community and get the full member experience.
Join For FreeThe release of Scala 2.13 had been in the works for quite a long time, but it was finally released last month. With the release of this version, there are quite a few changes that Scala has brought for the users.
The intent of this post is to explain some of the features Scala has introduced/improved since its previous version.
In this article, we focus on new features that Scala 2.13 has in store for users and whether you should migrate to Scala 2.13. I'll try to summarize all related knowledge in this blog, including documentation and the release notes as well.
With the latest release of Scala, there is a long list of important changes and improvements in several key areas: Collections, Standard library, Language, and the Compiler.
Let's try to get a better understanding of these.
The redesigning of the collections framework is one of the major changes that Scala has implemented in this new release.
Additionally, the Standard library collections have been overhauled for simplicity, performance, and safety.
Apart from the changes listed, most ordinary code that used the old collections will continue to work as-is. The most important collections changes include:
- Simpler method signatures
- The resulting library is easier to understand (in code, Scaladoc, and IDE code completion).
- It also makes user code compile faster.
- Simpler type hierarchy
- Parallel collections are now a separate module as a result of which
GenSeq
,GenTraversableOnce
, etc. are gone. Traversable
andTraversableOnce
are now only deprecated aliases forIterable
andIterableOnce
.
- Parallel collections are now a separate module as a result of which
- Immutable
scala.Seq
- Simplified views that work
- New, faster
HashMap
/Set implementation - New concrete collections
This is one of the main attractions in Scala 2.13. With the introduction of these new collections, Scala has really outsmarted its previous versions. Some of these new concrete collections include :immutable.LazyList
replacesimmutable.Stream
.immutable.ArraySeq
is an immutable wrapper for an array; there is also a mutable versionmutable.CollisionProofHashMap
guards against denial-of-service attacksmutable.ArrayDeque
is a double-ended queue that internally uses a resizable circular buffer.mutable.Stack
was reimplemented (and underappreciated)
- New abstract collection type
SeqMap
immutable.SeqMap
provides immutable maps that maintain insertion order.- Implementations of
VectorMap
andTreeSeqMap
also added in addition to the already existingListMap
.
These were some of the major changes in the collections made by Scala. Apart from these, there are a lot of additional changes as well. If you want to explore more on the same, you can go through them here.
The next big thing in the list of changes that Scala made in its latest version is additions and changes, as well as deprecations and removals to the standard library.
We will try to bifurcate some of those into the following categories:
- Integrated Java interop: The old
scala-java8-compat
module provides converters for options, function types, and Java streams. scala.util.Using
uses the loan pattern to provide a simple form of automatic resource management.- New chaining operations like
pipe
andtap
- New orderings like
Ordering.Double.TotalOrdering
andOrdering.Float.TotalOrdering
.toIntOption
feature parse literals and efficiently reject invalid input without throwing exceptions.- Library fits in compact1 profile reducing deployment footprint for Scala applications.
PartialFunction
now overloadsandThen
.- Undeprecate
linesIterator
to avoid conflict with JDK 11'sString.lines
- Replaced
Cloneable
/Serializable
traits with type aliases Future
is faster and more robust- String-building using
+
with a non-String
type on the left (akaany2stringadd
) is deprecated. - The following modules are no longer included in the distribution: scala-xml, scala-parser-combinators, scala-swing.
- Right projections on
Either
are deprecated. - Assorted deprecated methods and classes throughout the standard library have been removed entirely.
Additions
Deprecations and Removals
Although version 2.13 os Scala is stated as primarily a library release, not a language/compiler release, there are quite a few language changes including some new features, experimental features, and some deprecations:
- Literal types
- Partial unification on by default
- By-name implicits with recursive dictionaries
- Underscores in numeric literals
Experimental Features
- Symbol literals deprecated
- Symbols themselves remain supported, only the single-quote syntax is deprecated.
- Deprecated:
'foo
- Use instead:
Symbol("foo")
postfixOps
syntax disabled by default- The syntax, already deprecated in 2.12, causes an error in 2.13 unless the feature is explicitly enabled.
- Cause of Error:
xs size
- Use instead:
xs.size
Apart from these changes, there are a few more adjustments that are made with respect to the Language changes. For that, you can refer to the release notes.
Compiler
Last, but not the least, the team has invested heavily in compiler speedups during the 2.13 cycle, which resulted in some major changes with respect to the compiler.
Compiler performance in 2.13 is 5-10 percent better compared to 2.12, thanks mainly to the new collections.
Apart from this improvement in performance, Scala also claims to have more deterministic output and improved optimizer in this version.
Some of the major compiler changes that helped in improvement in performance include:
- Deterministic, reproducible compilation The compiler generates identical output for identical input in more cases, for reproducible builds.
- Optimizer improvements Operations on collections and arrays are now optimized more, including improved inlining.
- Compiler suggests possible corrections for unrecognized identifiers
- The scala-compiler JAR no longer depends on scala-xml
- Apart from this, there are a few changes to the scala compiler options as well.
In this blog, we tried to cover most of the major changes that Scala has added into the latest release. So, it's up to you to answer the question `Has Scala done it again?` with Scala 2.13.
If you want to explore more about Scala 2.13, you can go through the release notes.
Hope this helps. For any queries, feel free to leave a comment.
Stay tuned for more!
Published at DZone with permission of Anmol Sarna, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments