Programming language scala 3 is ready: less is more

Programming language Scala 3 is ready: less is more

The long-awaited new major version of the scala 3 programming language is now ready. Even if an official envision is still protruding when writing this message, the released github repository is the release 3.0.0 of dotty ready. The dotty project started in parallel to the regular development of scala, eight years ago with the declared goal, how a new scala can look like.

The scala inventor martin orky explained in 2018 in an interview with heise developer, that dotty is to become the basis for scala 3. Ultimately, the release scheduled at the end of 2019 was rejoined by one and a half years, but already last year most important amendments were fixed. The first milestone build appeared in november 2020, and from february to may this year, three release candidates paved the way to the now published stable release.

Scala combines functional and object-oriented programming

Scala now looks back on a twenty-year history. Martin odsky started working on the programming language in 2001 internally at the ecole polytechnique federale de lausanne (epfl). In the spring of 2004, scala for the java platform has been published, and in june followed a variant for .Net.

Scala is both functional and object-oriented. In addition, the programming language is highly typed and expandable. The functional portion is printed out, among other things, that functions are full-fledged speech elements that are stored in variables and give them as parameters. With regard to object-oriented programming, scala is "pure" as java: everything is an object, so for example, to call a simple array or a number a method, which accounts for autoboxing or unboxing.

The type of each variable is exactly defined, and scala uses type inference to detect the appropriate type from the initialization of variables. The extensibility is on the one hand a strong of the programming language, but on the other hand a hurde when entering scala. This allows you to write individual libraries whose content is quasi of identical to integrated voice features.

Scala 3: slight and accessible

While scala 2 followed the first version in 2006, the team liked the team with the now published scala 3 significantly more time. The new main version is aimed primarily on the simpler handling of the language and cleaner code. This means partly the merging of language constructs and the elimination of discrepancies.

The substantive innovations of dotty or scala 3 describes an article heise developer extensive. Noteworthy are the pasting or "recovery" the powerful implicit. Background is that some have used the powerful language feature too frequently or in the wrong context. So the new keyword given instead of implicit should describe the intention clearer. In the final spurt, a small change has been incorporated in the milestone build 3, which also removes the as from patterns.

Highest level

An important assessment are also toplevel definitions: so far developers and developers were allowed to define constructs such as types, methods or type aliases only in classes, traits or objects. Scala 3, however, allows definitions outside these elements on the top level. The in scala 2.8 enforced package objects are thereby slack. The new type of definition does not have to be done as with the package objects in its own package.

The complicated handling of payments is obedient to the criticisms on "old" scala, with sealed case objects and extensions of scala.Enumeration two approaches offered that both have their swuck. Scala 3 is therefore the almost excessive enum, which is also possible to use as in java and other programming languages and be more flexible about it. The new scala enumerations can be compared to the fruheren scala.Use enumeration from java code. Prerequisite is merely that you are from java.Long.Enum are derived. The payments can also be parameterized as in the following example from the documentation:

enum color (val rgb: int): case red extends color (0xff0000) case green extends color (0x00ff00) case blue extends color (0x0000ff)

Either type a or type b

B specifies that a value at a time is either type a or type b. In the way you allow a flexible but typical code: when using another type, the compiler throws an error. The implementation of the same logic about inheritance is also possible, but requires more code and a detailed planning of the class hierarchy.

Conversely, the newly introduced intersection type on the and operator define that a value defined as a b must be at the same time both type a and type b. In the way, the methods of both types can be used for the value.

Syntactic sugar and more

Scala 3 forces cleanly-opened code, and the compiler spits an error message for false candidations. The latter, however, can be deactivated via the compiler parameter -no-indent. For cleanly opened code, recently curly braces for blocks are eliminated. Details can be found in the documentation. The compiler should also output more understandable error messages with associated assistance, which indicate the causal source of the error.

Overall, scala 3 actually looks more clearer than the transaction versions. How far the changes can attract new developers will show. Anyone who has already loved the language, but has previously been backed up, probably finds the best time to get started. On the scala 3 site there is an entry-level assistance. The extensive innovations, however, mean a conversion for experienced scala developers. For her, the scala team published a migration guide of scala-2 projects to scala 3.

The release notes on github drove only a fixed typo compared to the last release candidate. In addition, the implementation of the typed abstract syntax trees tasty is no longer marked experimentally . The large part involves the additional payment of the persons who contributed to the project: the list shows a total of 358 developers and developers. Little surprisingly linguerfinder martin orky with 8661 commits did the lowenant part of contributing.

Leave a Comment