Google's Dart language soon won't take null for an answer
(2022/12/09)
- Reference: 1670549174
- News link: https://www.theregister.co.uk/2022/12/09/google_dart_null_safety/
- Source link:
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 [1]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 – [2]an issue to this day.
Dart, an object-oriented, garbage-collected C-like language that [3]once aspired to replace JavaScript, supported [4]sound null safety – a way to prevent errors from accessing variables set to null – [5]as of version 2.12 . But it maintained modes for running code without null safety or with partial null safety.
[6]
Dart 3 will no longer entertain those suboptimal possibilities.
[7]
[8]
"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 [9]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 [10]has exceptions .
[11]Meta met a programming language it likes better than Java
[12]Swift 5.5 unleashed with async keyword to fix 'pyramid of doom', plus other changes in 'massive release'
[13]Google's multi-platform app framework Flutter reaches version 2, expands to the web
[14]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 [15]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.
[16]
German automaker BMW recently managed a null safety code revision for its MyBMW app, which was [17]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 [18]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 [19]WasmGC extension . ®
Get our [20]Tech Resources
[1] https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/
[2] https://github.com/search?l=Dart&q=%22called+on+null%22&type=Issues
[3] https://www.informationweek.com/mobile/google-launches-dart-programming-language
[4] https://dart.dev/null-safety
[5] https://www.theregister.com/2021/03/03/google_allinone_app_framework_flutter/
[6] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0
[7] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0
[8] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0
[9] https://medium.com/dartlang/the-road-to-dart-3-afdd580fbefa
[10] https://kotlinlang.org/docs/null-safety.html#nullable-types-and-non-null-types
[11] https://www.theregister.com/2022/10/25/meta_java_kotlin/
[12] https://www.theregister.com/2021/09/22/swift_5_5_released_with_async/
[13] https://www.theregister.com/2021/03/03/google_allinone_app_framework_flutter/
[14] https://www.theregister.com/2021/02/02/patching_apache_rust/
[15] https://dart.dev/tools/pub/pubspec
[16] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0
[17] https://www.press.bmwgroup.com/global/article/detail/T0328610EN/the-my-bmw-app:-new-features-and-tech-insights-for-march-2021?language=en
[18] https://survey.stackoverflow.co/2022/#most-popular-technologies-webframe
[19] https://github.com/WebAssembly/gc/blob/master/proposals/gc/Charter.md
[20] https://whitepapers.theregister.com/
Null in this context is an assignment value indicating the absence of a value or referenced object. Null references [1]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 – [2]an issue to this day.
Dart, an object-oriented, garbage-collected C-like language that [3]once aspired to replace JavaScript, supported [4]sound null safety – a way to prevent errors from accessing variables set to null – [5]as of version 2.12 . But it maintained modes for running code without null safety or with partial null safety.
[6]
Dart 3 will no longer entertain those suboptimal possibilities.
[7]
[8]
"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 [9]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 [10]has exceptions .
[11]Meta met a programming language it likes better than Java
[12]Swift 5.5 unleashed with async keyword to fix 'pyramid of doom', plus other changes in 'massive release'
[13]Google's multi-platform app framework Flutter reaches version 2, expands to the web
[14]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 [15]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.
[16]
German automaker BMW recently managed a null safety code revision for its MyBMW app, which was [17]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 [18]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 [19]WasmGC extension . ®
Get our [20]Tech Resources
[1] https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/
[2] https://github.com/search?l=Dart&q=%22called+on+null%22&type=Issues
[3] https://www.informationweek.com/mobile/google-launches-dart-programming-language
[4] https://dart.dev/null-safety
[5] https://www.theregister.com/2021/03/03/google_allinone_app_framework_flutter/
[6] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0
[7] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0
[8] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0
[9] https://medium.com/dartlang/the-road-to-dart-3-afdd580fbefa
[10] https://kotlinlang.org/docs/null-safety.html#nullable-types-and-non-null-types
[11] https://www.theregister.com/2022/10/25/meta_java_kotlin/
[12] https://www.theregister.com/2021/09/22/swift_5_5_released_with_async/
[13] https://www.theregister.com/2021/03/03/google_allinone_app_framework_flutter/
[14] https://www.theregister.com/2021/02/02/patching_apache_rust/
[15] https://dart.dev/tools/pub/pubspec
[16] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Y5LA7uMsP90J@qHz4xNyrwAAAJE&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0
[17] https://www.press.bmwgroup.com/global/article/detail/T0328610EN/the-my-bmw-app:-new-features-and-tech-insights-for-march-2021?language=en
[18] https://survey.stackoverflow.co/2022/#most-popular-technologies-webframe
[19] https://github.com/WebAssembly/gc/blob/master/proposals/gc/Charter.md
[20] https://whitepapers.theregister.com/
NULL is just the pointer analog to NaN
Its actually useful having a value that represents 'no value' provided you are prepared to use it as such. There's lots of reasons why you might want to have a variable holding a location in memory and there are going to be times when it won't have anything useful in it. If you assume you can't do this then you'll just have to create with every pointer the thing its pointing to; it won't necessarily have valid data, of course, so all you've done is move the problem one level. Having a concept like floating point's NaN is very useful in this situation.
The present situation is only undesirable because we insist on trying to give an empty pointer a value that resolves to something tangible like zero. This invites people to tinker with addresses as if they're integers. It also resolves to a location in memory which prevents the processor trapping out with a data segment access fault -- the code blithely collects what's in that location and makes use of it to cause a problem.