Dart 2.12 available with sound null safety and FFI
The latest version of the programming language Dart is now available. Dart 2.12 includes stable versions of sound null safety and Dart FFI.
Null safety strengthens the language’s type system, and will enable developers to more easily catch null errors during development. Previously, it was difficult to tell the difference between code that anticipated being passed as null versus code that didn’t work with nulls. This resulted in a lot of bugs passing through, even after rigorous code reviews, and possibly going unnoticed for years, in some cases.
Null safety is a major change to the language, and requires a few changes when coding. Developers that want to create a variable that can contain either a null or a value will need to make that explicit when declaring a variable by adding a ? to the end of the type. There is also a new “required” keyword that produces an error when a parameter is marked as “required” and the caller forgets to provide the argument.
Null safety will be offered as an incremental migration, so developers can use Dart 2.12 without taking advantage of this feature. This is because the team believes it is too big of a change to force people into.
FFI is an interoperability mechanism enabling developers to invoke existing code that is written in C. Sample use cases the team has already seen include using the open_file API to invoke operating system APIs on Windows, macOS, and Linux; calling Windows Win32 APIS; objectbox, which is a fast database that uses a C-based implementation; and tflite_flutter, which uses FFI to wrap the TensorFlow Lite API.
Now that the core platform for FFI is complete, the team will be shifting its focus to expanding the FFI feature set. It is currently investigating adding features such as ABI-specific data types, inline arrays in structs, packed structs, union types, and exposing finalizers to Dart.
Future plans for Dart overall in the next release will mainly be focused on incremental language changes, such as type aliases, triple-shift operator, generic metadata annotations, and static meta-programming.
Credit: Source link