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 enables developers to quickly catch invalid 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 many bugs passing through, even after rigorous code reviews, and possibly going unnoticed for years, in some cases.
Null safety is a significant change to the language and requires a few differences when coding. Developers who want to create a variable containing either an invalid or a value will need to make that explicit when declaring a variable by adding a ? to the end of the type. A new “required” keyword 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; object box, 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 instructs, packed structs, union types, and exposing finalizers to Dart.
In the next release, future plans for Dart will mainly be focused on incremental language changes, such as type aliases, triple-shift operators, generic metadata annotations, and static meta-programming.