Scala 3 revolutionizes the language for a better experience for developers

architecture

InfoQ live on July 20. Speed up your software delivery without quality issues. Sign up now!

Scala 3 has overhauled the language for a better developer experience

Like printing bookmarks

Jun 24, 2021 3 min read

The author

  • Carsten Syertz

Eight years, 28,000 commits, 7,400 pull requests, and 4,100 closed questions later, Scala 3.0 has been released, providing a “complete overhaul of the Scala language,” including new features, an update to the syntax and type system, and new tools for metaprogramming. Scala Compatibility Reference hailed release 3 as a “game changer” [……] It will greatly improve the everyday experience of every Scala programmer. Scala 3 is binary compatible with Scala 2.13, but not completely source compatible. The new Dotty compiler can automatically migrate old code and report any legacy issues.

Scala 3.0’s new syntax is much more concise. The new keyword is now optional (similar to the feature Google introduced in Dart 2.0), as are the parentheses in control structure expressions. Some of the curly braces that occur can be replaced with source indentation, a well-known feature of Python.

New language features allow developers to express their intentions directly with questionable context abstractions: Using clauses and Given instances simplify context parameters, extension methods are first-class language citizens, and implicit transformations are now built as instances of the Scala.conversion class.

The type system has also been improved, such as simplified enumerations; Opaque types that hide implementation details Provide A | B and A & B respectively crossover and joint type of grammar; New dependent function types, whose results depend on the parameters of the function; And lambdas, the built-in type that used to require a compiler plug-in in Scala 2.

The enumeration syntax in Scala 2 is verbose. Take a look at the following example.

sealed trait Direction 
case object East extends Direction
case object West extends Direction
Copy the code

Scala 3 introduces a more concise syntax.

enum Direction:
   case: East.West
Copy the code

Functional programming has been simplified with the redesign of context abstractions and changes to the type system. Object-oriented development has also been improved, with new features including: Traits accept parameters and is declared (transparent) (https://dotty.epfl.ch/docs/reference/other-new-features/transparent-traits.html); An open modifier that explicitly marks the class as an open extension; In the spirit of encouraging decorators to design patterns in favor of composition over inheritance, define aliases for selected members of the object by providing an export clause.

Macros, first introduced in Scala 2.10, are an experimental feature. Scala 3 introduces a set of metaprogramming tools that feature inline methods to improve application performance; Compile-time operations that can be used with inline methods; Reference code blocks to build and analyze code; And the reflection API to provide a view of the typed abstract syntax tree including the TASTy file. The Scala 3 macro is designed to ensure stability and will be compatible with future versions of Scala. However, under this new metaprogramming model, Scala 2.13 macros will need to be rewritten. In addition, many Scala 2 [scaladoc] (https://docs.scala-lang.org/style/scaladoc.html) Settings have changed, so that the parameters in the Scala 3 standardization.

New compiler options such as -xignore-scala2-macros ignore compiler errors in code that calls Scala 2 macros; -print-tasty prints the original tasty file; -no-indent will execute classical syntax, and these are just some of the many new options for compiling code. The Migration guide details the migration to Scala 3 and includes a tutorial on porting a complete Scala 2.13 project to Scala 3.

A Scala 3.0 application can still use a Scala 2.13 library, even with macros — unless a non-working macro breaks the library. Vice versa, for example, a Scala 2.13 application can use Scala 3.0 libraries. The Scala Library Index, also known as Scaladex, lists which libraries are ready for Scala 3.0.

However, these changes come at a cost, as some Scala 2.13 source code is incompatible with Scala 3.0. Fortunately, the new compiler includes a migration mode that automatically migrates Scala 2 code to Scala 3 and reports any remaining problems that need to be fixed manually.

More information about Scala 3 can be found in the new Content section of the site.

The easiest way to get started with Scala 3.0 is to use Scastie, Scala’s online IDE, which allows you to write and execute code directly from the browser. It also shows how to run a “Hello, world “program.

Five weeks after its release, the Documentation and book for Scala 3.0 are not yet complete, and we encourage the Scala community to contribute.

After 3.0, new Scala releases are expected every six weeks. Developers can expect the next release at the end of June 2021.

How can we improve InfoQ for you

Thank you for being a reader of InfoQ.

Every year, we seek feedback from our readers to help us improve InfoQ. Would you mind taking 2 minutes to share your feedback in our short survey? Your feedback will directly help us continuously improve our support to you.

Participate in the survey

Grade the article

adopt

style

Contact author

This content belongs toJavaThe theme

Related topics.
  • The development of

  • architecture

  • architecture

  • Architectural language

  • architecture

  • Related to edit

  • Related sponsorship content

    • Review the IMPLEMENTATION of the JDK carefully
  • Related Sponsors

    Modern application development. , enterprise software that supports Jakarta EE and MicroProfile applications. Learn more.

The related content

  • JDK internal elements are forcefully wrapped in JDK 17
  • Java News Roundup – Week of June 14, 2021
  • What is the “Taobao customer” on Taobao?
  • Java News Roundup – Week of June 7, 2021
  • Java News Roundup – Week of May 31, 2021
  • Taobao releases open source JDBC-over-HTTP driver
  • Implement microservitization with Istio

  • What is sold on Taobao?
  • Java News Roundup – Week of May 24, 2021
  • The path to Quarkus 2.0. Architect: Continuous testing
  • Use JReleaser for fast, seamless release management of Java projects

  • New in Java 16

  • Google has revamped Android Material Design, improved the UI toolkit and Android Studio
  • Jolie– Service-oriented Distributed application programming language
  • GraalVM 21.1 supports JDK 16
  • Taobao on the “Taobao guest” is how lian become?

  • Do serverless search for my blog using Java, Quarkus, and AWS Lambda

  • Implement microservitization with Quarkus and MicroProfile

  • Upgrade to Java 16 or 17

    ! [Upgrade to Java 16 or 17](https://res.infoq.com/presentations/upgrade-java16-java17/en/smallimage/Johan Janssen-s-1620161865580.jpg)

  • Run the Axon server in the virtual machine

  • Article series. Build microservices in Java

  • Quick start: Explore Java’s static compilation environment

    ! [Starting Fast: Investigating Java’s Static Compilation Landscape](https://res.infoq.com/presentations/java-start-fast-graal-substrate/en/smallimage/Dan Heidinga-s-1617917709685.jpg)

  • Enabling Java. Windows on Arm64 – A success story

  • Test the Quarkus Web application. Reactive messaging, Kafka, and test containers

  • So the project. Bring performance to Java developers

    ! [Project Valhalla: Bringing Performance to Java Developers](https://res.infoq.com/presentations/valhalla-memory-density/en/smallimage/Tobi Ajila-s-1614698768877.jpg)

  • Test the Quarkus Web application. Write concise component tests

  • Test the Quarkus Web application. Component and integration testing

  • Virtual panels: The impact of Microprofiles on microservices frameworks

  • Enhance flow processing with Kotlin’s Sequence interface

  • Java features focus. Pattern matching

  • Donkey: Clojure’s high-performance HTTP stack

  • Terraform 1.0 adds stability assurance and an improved upgrade experience
  • From procedure to process, designed for workplace equality

  • Validation of autonomous systems

  • Google introduces new cloud TPU virtual machines for AI workloads
  • Google trains 2 billion parameter AI vision models
  • .NET News Roundup:.NET 6, MAUI, EF Core 6, Visual Studio 2022
  • Google’s UI toolkit, Flutter 2.2, dominates the cross-platform space
  • Evolving analytics in data platforms

  • Leveraging small teams to extend Agility — a Red Hat case study

interviews

InfoQ’s roundup of the past week, delivered every Tuesday. Join a community of more than 250,000 senior developers. See the sample

Enter your email address

Choose your Country I consent to InfoQ.com processing my data as explained in this Privacy Statement.

We protect your privacy.

Stranger hello!

You need to sign up for an InfoQ account or login, or after login, to post comments. But there’s a lot going on behind the registration.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed HTML: a, b, br, blockquote, I, li, the pre, u, ul, p

Email me in response to any messages I have in this subject

Community comments

Observe the theme

Shut down

Your reply

Citing original information

Allowed HTML: a, b, br, blockquote, I, li, the pre, u, ul, p

Email me in response to any messages I have in this subject

cancel

Shut down

Your reply

Allowed HTML: a, b, br, blockquote, I, li, the pre, u, ul, p

Email me in response to any messages I have in this subject

cancel

Shut down

recognition

discuss