Dart 2.7 adds support for extension methods & null safety preview

Share
  • December 13, 2019

With the release of Flutter 1.12, Dart 2.7 also arrives, adding a new long-awaited feature: extension methods.

Was 2019 the year of Dart? In January 2019 our readers voted and they said that they wanted to hear about Dart over other programming languages. Meanwhile, GitHub’s State of the Octoverse revealed Dart as the fastest-growing language according to the number of contributors.

Developed by Google, Dart is an open source, client-optimized language that can compile to JavaScript for the web or to ARM and x64 machine code for mobile, desktop, and backend.

Let’s look at the release highlights and the two big new features.

Extension methods

The most anticipated addition arriving in 2.7 is the introduction of extension methods.

SEE ALSO: DevOpsCon Munich 2019 takeaways: Everyone is in Ops now & more

From the release announcement post by Product Manager Michael Thomsen:

Dart 2.7 adds a long-requested, powerful new language feature: extension methods. These enable you to add new functionality to any type — even types you don’t control — and have the brevity and auto-complete experience of regular method calls.

According to Thomsen, extension methods are resolved and dispatched statically and can have type variables. Extension methods help add functionality to libraries and work just as fast as calling static functions. Using extension methods is as simple as importing the library they are contained in.

View the guide to learn more about them and their API conflicts. Lasse Reichstein Holst Nielsen, one of the creators of the features, explains in-depth how to use extension methods in an article titled Dart Extension Methods Fundamentals.

    International JavaScript Conference
    Manfred Steyer

    The Future of Angular and your Architectures with Ivy

    by Manfred Steyer (SOFTWAREarchitekt.at)

    Andrey Goncharov

    React: Lifting state up is killing your app

    by Andrey Goncharov (Hazelcast)

    Previewing null safety

    While it isn’t fully stable yet, null safety gets an update; null safety static analysis is now available for preview. Get some hands-on experience and test out some samples in the new null safety playground in DartPad.

    With null safety, Dart will show any errors related to declaring variables as null without running the code. From there, you can make edits, fix the mistakes, and achieve safe code.

    Analysis errors. Source.

    Once null safety reaches beta, devs will be able to use it in their apps and packages.

    Keep an eye out for upcoming new features. According to the announcement post, work is currently underway on porting the Dart core libraries, adding a migration tool, and completing nullable and non-nullable references.

    This preview is opt-in, so you can start using it whenever you are ready.

    SEE ALSO: The Future of Angular and your Architectures with Ivy

    Check out 2.7

    How can Dart top its performance in 2019? The upcoming plans for 2020 include stable versions of dart:ffi and of course, further work on null safety.

    Download the newest SDK and see the latest features for yourself or check it out on GitHub.

    It is also included in Flutter 1.12 and in the newest version the in-browser editor DartPad, which includes all of Flutter’s core libraries.

    The post Dart 2.7 adds support for extension methods & null safety preview appeared first on JAXenter.

Source : JAXenter