The Dart programming language has reached a new major milestone with the technical preview of its new null safety feature, the Dart team announced. According to the team, this feature has been in development for over a year, and is the biggest addition to the Dart language since Dart 2

“Null safety helps you avoid a class of bugs that are often hard to spot, and as an added bonus enables a range of performance improvements,” team members Filip Hracek and Michael Thomsen wrote in a post

Dart is a type-safe language, meaning that the compiler can guarantee that a variable is of the type the developer believes it is. But according to the Dart team, this type safety doesn’t actually guarantee that the variable isn’t null. In Dart, null errors are very common, and thousands of GitHub issues and commits are a result of them. 

Null safety provides developers with a guarantee that their code doesn’t contain null elements. It will provide static errors as code is typed so that developers don’t have to wait until the code is compiled runtime to discover errors. Instead, null safety provides static errors as code is written.

When designing this feature, the Dart team had three core principles in mind. First, it must be non-nullable by default, so that developers would have to explicitly state when a variable can actually be null. Second, it had to be incrementally adoptable, meaning that null-safe and non-null-safe code could exist together in the same project. Third, it had to be fully sound. 

According to the team, Dart’s null safety is backwards compatible and is not a breaking change. This means that existing code can call code that uses null safety, and null safety will be an optional feature once it is available. 

While still in the early stages, the team hopes to release null safety as a stable feature by the end of 2020. Between now and then it will add a number of new features to complement this feature, such as a migration tool, tags on pub.dev that reveal if a package supports null safety, and an extension to the “pub outdated” command that adds support for finding versions of dependencies that support null safety. 

More information on null safety and code examples of it is available here