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 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.
- Meta met a programming language it likes better than Java
- Swift 5.5 unleashed with async keyword to fix 'pyramid of doom', plus other changes in 'massive release'
- Google's multi-platform app framework Flutter reaches version 2, expands to the web
- In Rust we trust: Shoring up Apache, ISRG ditches C, turns to wunderkind lang for new TLS crypto module
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."
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. ®