The general-purpose programming language developed by Google, Dart is easy to learn, scalable and deployable everywhere; now it has sound null safety in the works.
While null safety help developers avoid a class of hard to spot bugs when they opt for it, their codes are made non-nullable by default, meaning that the values cannot be null unless specifically made to be so. With null safety, the runtime null-dereference errors turns to edit-time analysis errors.
Dart’s null safety which is still in preview, is perhaps the biggest addition to the programming language since the release of Dart 2 in August 2018.
Overview of the Dart’s sound null safety
Dart's sound null safety analyzes code, to determine that a variable is non-nullable and ensures that it's always non-nullable. The compiler can then produce smaller and faster code as it doesn't need to add checks for nulls when it already knows a variable is not null.
As null safety is backward compatible, it will serve as an optional feature, allowing developers to be able to adopt it whenever they’re ready and the Dart core libraries have also been migrated to use null safety.
The fundamental design of Dart's null safety includes the fact that developers must explicitly note that a variable can be null, or it'll be considered non-nullable. And it is incrementally adoptable, with tools made available to help with migration.
Getting Started with Dart’s sound null safety
If you want to test the Dart’s sound null safety feature, it is currently available for testing in this version of DartPad, and also due in a production-ready Dart release by the end of 2020.
The null safety version of DartPad is the first in a series of code examples designed to illustrate the new syntax and coding patterns for null safety.
And each snippet starts off in a bad or broken state. Therefore, you’ll probably encounter warnings from the Dart analyzer, or the code probably won't compile. But by simply following the instructions and making some edits to the code, you can be able to update each snippet to a working state.