22

Scala 2.13: Has Scala Done it Again?

 4 years ago
source link: https://www.tuicool.com/articles/UJ7nq2M
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The 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.

rYr6fq2.png!web

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.

nEVjuaJ.png!web

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 and TraversableOnce are now only deprecated aliases for Iterable and IterableOnce .
  • 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 replaces immutable.Stream .
    • immutable.ArraySeq is an immutable wrapper for an array; there is also a mutable version
    • mutable.CollisionProofHashMap guards against denial-of-service attacks
    • mutable.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 and TreeSeqMap also added in addition to the already existing ListMap .

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.

nmmIN3F.png!web We will try to bifurcate some of those into the following categories:

Additions

  • 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 and tap
  • New orderings like Ordering.Double.TotalOrdering
    and Ordering.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 overloads andThen .
  • Undeprecate linesIterator to avoid conflict with JDK 11's String.lines
  • Replaced Cloneable / Serializable traits with type aliases
  • Future is faster and more robust

Deprecations and Removals

  • String-building using + with a non- String type on the left (aka any2stringadd ) 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.

Rb2673I.gif 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
    'foo
    Symbol("foo")
    
  • postfixOps syntax disabled by default
    xs size
    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

eyIJ3uz.png!web 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!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK