DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Modernizing Apache Spark Applications With GenAI: Migrating From Java to Scala
  • Mastering Advanced Aggregations in Spark SQL
  • Thermometer Continuation in Scala
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Trending

  • Skills, Java 17, and Theme Accents
  • AI Agents in Java: Architecting Intelligent Health Data Systems
  • S3 Vectors: How to Build a RAG Without a Vector Database
  • Solving the Mystery: Why Java RSS Grows in Docker on M1 Macs
  1. DZone
  2. Coding
  3. Languages
  4. Scala 2.13: Has Scala Done it Again?

Scala 2.13: Has Scala Done it Again?

Scala 2.13: Is it worth the hype?

By 
Anmol Sarna user avatar
Anmol Sarna
·
Jul. 15, 19 · Analysis
Likes (9)
Comment
Save
Tweet
Share
25.5K Views

Join the DZone community and get the full member experience.

Join For Free

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.

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


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
      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 overloads andThen.
    • Undeprecate linesIterator to avoid conflict with JDK 11's String.lines
    • Replaced Cloneable/Serializabletraits 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.


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!

Scala (programming language)

Published at DZone with permission of Anmol Sarna. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Modernizing Apache Spark Applications With GenAI: Migrating From Java to Scala
  • Mastering Advanced Aggregations in Spark SQL
  • Thermometer Continuation in Scala
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook