Google's Dart language soon won't take null for an answer

Unavoidable variable safety coming in version 3

When the third major release of the Dart programming language debuts in mid-2023, null values will no longer be allowed where they're not expected.

Null in this context is an assignment value indicating the absence of a value or referenced object. Null references date back to around 1964 when British computer scientist Tony Hoare introduced the concept in the ALGOL family of languages. He considered them his "billion dollar mistake" for the amount of time and money they've cost in error repairs – an issue to this day.

Dart, an object-oriented, garbage-collected C-like language that once aspired to replace JavaScript, supported sound null safety – a way to prevent errors from accessing variables set to null – as of version 2.12. But it maintained modes for running code without null safety or with partial null safety.

Dart 3 will no longer entertain those suboptimal possibilities.

"Our next release, Dart 3, completes the journey to a fully sound null safe language," explained Michael Thomsen, product manager on Dart and Flutter, in a blog post. "As the last step of that journey, we’re removing several historical Dart language and SDK artifacts, including removing support for running without sound null safety."

Sound null safety, Thomsen explains, means that a non-nullable variable never contains a null value. Not every implementation of null safety is so certain: TypeScript, for example, is unsound – you can assign a null value to a non-null variable. C# has exceptions to its null checks. And Kotlin also has exceptions.

Dart's transition will help catch type-related bugs at compile time, and should improve code readability, maintainability, and ahead-of-time (AOT) compilation.

There's a cost however. Sound null safety will be the only option so pubspec files – Dart package metadata – with an SDK constraint set for less than 2.12 will no longer resolve in Dart 3. According to Thomsen, about 85 percent of Flutter code (which is written in Dart) supports sound null safety at this point. Those with apps and packages in the remaining 15 percent are urged to adapt their code prior to Dart 3's arrival.

German automaker BMW recently managed a null safety code revision for its MyBMW app, which was built with Dart framework Flutter. "While the migration to null-safety was certainly not easy for a large-scale codebase like the MyBMW app, Google’s tools gave us great assistance in the migration process," said Christian Schmid, head of mobile app development for BMW AG, in a statement. "After having the migration completed we enjoy having a less error-prone codebase."

Dart currently ranks 16th in programming language popularity per Stack Overflow's 2022 Developer Survey. Among close to 72,000 respondents, about 6.54 percent said they used Dart, compared to 9.16 percent for Kotlin (15th), 9.32 percent for Rust (14th), and 11.15 percent for Go (13th). Apple's Swift programming language ranked 19th, at 4.91 percent. The most widely used language among survey takers was JavaScript (1st), used by 65.36 percent.

Following the release of Dart 3, the next significant milestone for the language is likely to be support for compiling Dart code into WebAssembly (Wasm), which will allow Flutter Web apps to run as native code in browsers. That effort requires cooperation from the W3C and browser vendors to add support for garbage collected languages (like Dart) to Wasm by way of the WasmGC extension. ®

Similar topics

TIP US OFF

Send us news


Other stories you might like